Skip to content

Commit 37200d5

Browse files
gwram11
andcommitted
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 Let FilterArgType use struct FindData to simplify filters. Handle the possibility of finding d_type == DT_UNKOWN Add HAVE_DIRENT_D_TYPE introspection Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
1 parent 9fa4ca5 commit 37200d5

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

src/coreclr/tools/superpmi/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
include(configure.cmake)
2+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
3+
14
add_subdirectory(superpmi)
25
add_subdirectory(mcs)
36
add_subdirectory(superpmi-shim-collector)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#ifndef __CONFIG_H__
5+
#define __CONFIG_H__
6+
7+
#cmakedefine01 HAVE_DIRENT_D_TYPE
8+
9+
#endif // __CONFIG_H__
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include(CheckStructHasMember)
2+
3+
check_struct_has_member ("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)
4+
5+
configure_file(
6+
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
7+
${CMAKE_CURRENT_BINARY_DIR}/config.h)

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

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
#include "simpletimer.h"
77
#include "logging.h"
88
#include "spmiutil.h"
9+
#include "config.h"
910
#include <stdio.h>
1011
#ifdef TARGET_UNIX
1112
#include <sys/types.h>
1213
#include <dirent.h>
1314
#include <fnmatch.h>
14-
#endif
15+
#ifndef DT_UNKNOWN
16+
#define DT_UNKNOWN 0
17+
#define DT_DIR 4
18+
#define DT_REG 8
19+
#define DT_LNK 10
20+
#endif // !DT_UNKNOWN
21+
#endif // TARGET_UNIX
1522

1623
#include <utility>
1724

@@ -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,55 @@ 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+
struct stat sb;
292+
int dirEntryType;
293+
294+
#if HAVE_DIRENT_D_TYPE
295+
dirEntryType = pEntry->d_type;
296+
#else
297+
dirEntryType = DT_UNKNOWN;
298+
#endif
299+
// On some systems, dirent contains a d_type field, but note:
300+
// some file systems MAY leave d_type == DT_UNKNOWN,
301+
// expecting the consumer to stat the file. On systems
302+
// without a d_type simply always stat the file.
303+
304+
if (dirEntryType == DT_UNKNOWN)
285305
{
286-
FindData findData(pEntry->d_type, ConvertMultiByteToWideChar(pEntry->d_name));
306+
307+
if (fstatat(dirfd(pDir), pEntry->d_name, &sb, 0) == -1)
308+
continue;
309+
310+
if (S_ISDIR(sb.st_mode))
311+
dirEntryType = DT_DIR;
312+
else if (S_ISREG(sb.st_mode))
313+
dirEntryType = DT_REG;
314+
else if (S_ISLNK(sb.st_mode))
315+
dirEntryType = DT_LNK;
316+
else
317+
dirEntryType = DT_UNKNOWN;
318+
319+
}
320+
321+
if (dirEntryType == DT_UNKNOWN)
322+
{
323+
continue;
324+
}
325+
326+
if (fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) != 0)
327+
{
328+
continue;
329+
}
330+
331+
// Call the filter with &FindData like the Windows code below.
332+
FindData findData(dirEntryType, ConvertMultiByteToWideChar(pEntry->d_name));
333+
if (filter(&findData))
334+
{
335+
// Prepend it to the list.
287336
first = new findDataList(&findData, first);
288337
++elemCount;
289338
}
339+
290340
errno = 0;
291341
pEntry = readdir(pDir);
292342
}

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)