Skip to content

Prerequisite 4 for #105403 (src/coreclr/tools/superpmi) #117022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/coreclr/tools/superpmi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
include(configure.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_subdirectory(superpmi)
add_subdirectory(mcs)
add_subdirectory(superpmi-shim-collector)
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/tools/superpmi/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef __CONFIG_H__
#define __CONFIG_H__

#cmakedefine01 HAVE_DIRENT_D_TYPE

#endif // __CONFIG_H__
7 changes: 7 additions & 0 deletions src/coreclr/tools/superpmi/configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(CheckStructHasMember)

check_struct_has_member ("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
56 changes: 49 additions & 7 deletions src/coreclr/tools/superpmi/mcs/verbmerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
#include "simpletimer.h"
#include "logging.h"
#include "spmiutil.h"
#include "config.h"
#include <stdio.h>
#ifdef TARGET_UNIX
#include <sys/types.h>
#include <dirent.h>
#include <fnmatch.h>
#endif
#ifndef DT_UNKNOWN
#define DT_UNKNOWN 0
#define DT_DIR 4
#define DT_REG 8
#define DT_LNK 10
#endif // !DT_UNKNOWN
#endif // TARGET_UNIX

#include <utility>

Expand Down Expand Up @@ -187,9 +194,9 @@ bool verbMerge::DirectoryFilterDirectories(FilterArgType* findData)
#else // TARGET_WINDOWS
if (findData->d_type == DT_DIR)
{
if (strcmp(findData->d_name, ".") == 0)
if (u16_strcmp(findData->cFileName, W(".")) == 0)
return false;
if (strcmp(findData->d_name, "..") == 0)
if (u16_strcmp(findData->cFileName, W("..")) == 0)
return false;

return true;
Expand Down Expand Up @@ -281,12 +288,47 @@ int verbMerge::FilterDirectory(LPCWSTR dir,
dirent *pEntry = readdir(pDir);
while (pEntry != nullptr)
{
if ((fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) == 0) && filter(pEntry))
int dirEntryType;

#if HAVE_DIRENT_D_TYPE
dirEntryType = pEntry->d_type;
#else
struct stat sb;

if (fstatat(dirfd(pDir), pEntry->d_name, &sb, 0) == -1)
{
continue;
}

if (S_ISDIR(sb.st_mode)) {
dirEntryType = DT_DIR;
} else if (S_ISREG(sb.st_mode)) {
dirEntryType = DT_REG;
} else if (S_ISLNK(sb.st_mode)) {
dirEntryType = DT_LNK;
} else {
dirEntryType = DT_UNKNOWN;
}
#endif
if (dirEntryType == DT_UNKNOWN)
{
FindData findData(pEntry->d_type, ConvertMultiByteToWideChar(pEntry->d_name));
first = new findDataList(&findData, first);
++elemCount;
continue;
}

if (fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) != 0)
{
continue;
}

FindData findData(dirEntryType, ConvertMultiByteToWideChar(pEntry->d_name));
if (!filter(&findData))
{
continue;
}

first = new findDataList(&findData, first);
++elemCount;

errno = 0;
pEntry = readdir(pDir);
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/mcs/verbmerge.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class verbMerge
#ifdef TARGET_WINDOWS
typedef _WIN32_FIND_DATAW FilterArgType;
#else
typedef struct dirent FilterArgType;
typedef struct FindData FilterArgType;
#endif

typedef bool (*DirectoryFilterFunction_t)(FilterArgType*);
Expand Down
Loading