Skip to content

Commit 2dd616d

Browse files
committed
Fix compile errors in coreclr/tools/superpmi/mcs/merbmerge.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 2dd616d

File tree

1 file changed

+66
-6
lines changed

1 file changed

+66
-6
lines changed

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

Lines changed: 66 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.
@@ -185,7 +192,7 @@ bool verbMerge::DirectoryFilterDirectories(FilterArgType* findData)
185192
return true;
186193
}
187194
#else // TARGET_WINDOWS
188-
if (findData->d_type == DT_DIR)
195+
if (true)
189196
{
190197
if (strcmp(findData->d_name, ".") == 0)
191198
return false;
@@ -206,13 +213,32 @@ bool verbMerge::DirectoryFilterFile(FilterArgType* findData)
206213
{
207214
#ifdef TARGET_WINDOWS
208215
if ((findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
216+
{
217+
// This is not a directory, so it must be a file.
218+
return true;
219+
}
209220
#else // TARGET_WINDOWS
221+
222+
#if HAVE_DIRENT_D_TYPE
210223
if (findData->d_type != DT_DIR)
211-
#endif // TARGET_WINDOWS
212224
{
213225
// This is not a directory, so it must be a file.
214226
return true;
215227
}
228+
#else // HAVE_DIRENT_D_TYPE
229+
struct stat sb;
230+
231+
if (fstatat(dirfd(dir), entry->d_name, &sb, 0) == -1) {
232+
// stat failed. say "not a file" so caller will skip it
233+
return false;
234+
}
235+
if (!S_ISDIR(sb.st_mode)) {
236+
// Treat anything not a directory as a file.
237+
return true;
238+
}
239+
#endif // HAVE_DIRENT_D_TYPE
240+
241+
#endif // TARGET_WINDOWS
216242

217243
return false;
218244
}
@@ -281,12 +307,46 @@ int verbMerge::FilterDirectory(LPCWSTR dir,
281307
dirent *pEntry = readdir(pDir);
282308
while (pEntry != nullptr)
283309
{
284-
if ((fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) == 0) && filter(pEntry))
310+
int dirEntryType;
311+
312+
if ((fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) != 0)
285313
{
286-
FindData findData(pEntry->d_type, ConvertMultiByteToWideChar(pEntry->d_name));
287-
first = new findDataList(&findData, first);
288-
++elemCount;
314+
continue;
289315
}
316+
if (!filter(pEntry))
317+
{
318+
continue;
319+
}
320+
321+
#if HAVE_DIRENT_D_TYPE
322+
dirEntryType = pEntry->d_type;
323+
#else
324+
struct stat sb;
325+
326+
if (fstatat(dirfd(dir), pEntry->d_name, &sb, 0) == -1)
327+
{
328+
continue;
329+
}
330+
331+
if (S_ISDIR(sb.st_mode)) {
332+
dirEntryType = DT_DIR;
333+
} else if (S_ISREG(sb.st_mode)) {
334+
dirEntryType = DT_REG;
335+
} else if (S_ISLNK(sb.st_mode)) {
336+
dirEntryType = DT_LNK;
337+
} else {
338+
dirEntryType = DT_UNKNOWN;
339+
}
340+
#endif
341+
if (dirEntryType == DT_UNKNOWN)
342+
{
343+
continue;
344+
}
345+
346+
FindData findData(dirEntryType, ConvertMultiByteToWideChar(pEntry->d_name));
347+
first = new findDataList(&findData, first);
348+
++elemCount;
349+
290350
errno = 0;
291351
pEntry = readdir(pDir);
292352
}

0 commit comments

Comments
 (0)