Skip to content

Commit 20bc111

Browse files
committed
Fix compile errors in coreclr/tools/superpmi/mcs/verbmerge.cpp
/runtime/src/coreclr/tools/superpmi/mcs/verbmerge.cpp: In static member function 'static bool verbMerge::DirectoryFilterDirectories(FilterArgType*)': /runtime/src/coreclr/tools/superpmi/mcs/verbmerge.cpp:188:19: error: 'verbMerge::FilterArgType' {aka 'struct dirent'} has no member named 'd_type' 188 | if (findData->d_type == DT_DIR) | ^~~~~~ and similar a few other places in this file
1 parent a2e10a5 commit 20bc111

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

src/coreclr/tools/superpmi/mcs/verbmerge.cpp

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include <fnmatch.h>
1414
#endif
1515

16+
#if !HAVE_DIRENT_D_TYPE
17+
#define DT_UNKNOWN 0
18+
#define DT_DIR 4
19+
#define DT_REG 8
20+
#define DT_LNK 10
21+
#endif
22+
1623
#include <utility>
1724

1825
// Do reads/writes in large 256MB chunks.
@@ -187,9 +194,9 @@ bool verbMerge::DirectoryFilterDirectories(FilterArgType* findData)
187194
#else // TARGET_WINDOWS
188195
if (findData->d_type == DT_DIR)
189196
{
190-
if (strcmp(findData->d_name, ".") == 0)
197+
if (u16_strcmp(findData->cFileName, W(".")) == 0)
191198
return false;
192-
if (strcmp(findData->d_name, "..") == 0)
199+
if (u16_strcmp(findData->cFileName, W("..")) == 0)
193200
return false;
194201

195202
return true;
@@ -281,12 +288,47 @@ int verbMerge::FilterDirectory(LPCWSTR dir,
281288
dirent *pEntry = readdir(pDir);
282289
while (pEntry != nullptr)
283290
{
284-
if ((fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) == 0) && filter(pEntry))
291+
int dirEntryType;
292+
293+
#if HAVE_DIRENT_D_TYPE
294+
dirEntryType = pEntry->d_type;
295+
#else
296+
struct stat sb;
297+
298+
if (fstatat(dirfd(pDir), pEntry->d_name, &sb, 0) == -1)
299+
{
300+
continue;
301+
}
302+
303+
if (S_ISDIR(sb.st_mode)) {
304+
dirEntryType = DT_DIR;
305+
} else if (S_ISREG(sb.st_mode)) {
306+
dirEntryType = DT_REG;
307+
} else if (S_ISLNK(sb.st_mode)) {
308+
dirEntryType = DT_LNK;
309+
} else {
310+
dirEntryType = DT_UNKNOWN;
311+
}
312+
#endif
313+
if (dirEntryType == DT_UNKNOWN)
285314
{
286-
FindData findData(pEntry->d_type, ConvertMultiByteToWideChar(pEntry->d_name));
287-
first = new findDataList(&findData, first);
288-
++elemCount;
315+
continue;
289316
}
317+
318+
if (fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) != 0)
319+
{
320+
continue;
321+
}
322+
323+
FindData findData(dirEntryType, ConvertMultiByteToWideChar(pEntry->d_name));
324+
if (!filter(&findData))
325+
{
326+
continue;
327+
}
328+
329+
first = new findDataList(&findData, first);
330+
++elemCount;
331+
290332
errno = 0;
291333
pEntry = readdir(pDir);
292334
}

src/coreclr/tools/superpmi/mcs/verbmerge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class verbMerge
6565
#ifdef TARGET_WINDOWS
6666
typedef _WIN32_FIND_DATAW FilterArgType;
6767
#else
68-
typedef struct dirent FilterArgType;
68+
typedef struct FindData FilterArgType;
6969
#endif
7070

7171
typedef bool (*DirectoryFilterFunction_t)(FilterArgType*);

0 commit comments

Comments
 (0)