Skip to content

Commit 69d6a05

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 5865e2d commit 69d6a05

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

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

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
#include <sys/types.h>
1212
#include <dirent.h>
1313
#include <fnmatch.h>
14-
#endif
14+
#if !HAVE_DIRENT_D_TYPE
15+
#define DT_UNKNOWN 0
16+
#define DT_DIR 4
17+
#define DT_REG 8
18+
#define DT_LNK 10
19+
#endif // !HAVE_DIRENT_D_TYPE
20+
#endif // TARGET_UNIX
1521

1622
#include <utility>
1723

@@ -187,9 +193,9 @@ bool verbMerge::DirectoryFilterDirectories(FilterArgType* findData)
187193
#else // TARGET_WINDOWS
188194
if (findData->d_type == DT_DIR)
189195
{
190-
if (strcmp(findData->d_name, ".") == 0)
196+
if (u16_strcmp(findData->cFileName, W(".")) == 0)
191197
return false;
192-
if (strcmp(findData->d_name, "..") == 0)
198+
if (u16_strcmp(findData->cFileName, W("..")) == 0)
193199
return false;
194200

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

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)