summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Path.inc
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2019-07-18 20:05:11 +0000
committerJordan Rose <jordan_rose@apple.com>2019-07-18 20:05:11 +0000
commit887d31cceee27ffa9162486a86301a925f9c1d54 (patch)
tree630c90c1621e59d1d00779613afa749b697ee4c2 /llvm/lib/Support/Unix/Path.inc
parent9e52d0576ab7e6a3973f550b347b7f91c79d2521 (diff)
downloadbcm5719-llvm-887d31cceee27ffa9162486a86301a925f9c1d54.tar.gz
bcm5719-llvm-887d31cceee27ffa9162486a86301a925f9c1d54.zip
FileSystem: Check for DTTOIF alone, not _DIRENT_HAVE_D_TYPE
While 'd_type' is a non-standard extension to `struct dirent`, only glibc signals its presence with a macro '_DIRENT_HAVE_D_TYPE'. However, any platform with 'd_type' also includes a way to convert to mode_t values using the macro 'DTTOIF', so we can check for that alone and still be confident that the 'd_type' member exists. (If this turns out to be wrong, I'll go back and set up an actual CMake check.) I couldn't think of how to write a test for this, because I couldn't think of how to test that a 'stat' call doesn't happen without controlling the filesystem or intercepting 'stat', and there's no good cross-platform way to do that that I know of. Follow-up (almost a year later) to r342089. rdar://problem/50592673 https://reviews.llvm.org/D64940 llvm-svn: 366486
Diffstat (limited to 'llvm/lib/Support/Unix/Path.inc')
-rw-r--r--llvm/lib/Support/Unix/Path.inc5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index e80880c6b3c..908f43ed5a9 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -833,7 +833,10 @@ std::error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
static file_type direntType(dirent* Entry) {
// Most platforms provide the file type in the dirent: Linux/BSD/Mac.
// The DTTOIF macro lets us reuse our status -> type conversion.
-#if defined(_DIRENT_HAVE_D_TYPE) && defined(DTTOIF)
+ // Note that while glibc provides a macro to see if this is supported,
+ // _DIRENT_HAVE_D_TYPE, it's not defined on BSD/Mac, so we test for the
+ // d_type-to-mode_t conversion macro instead.
+#if defined(DTTOIF)
return typeForMode(DTTOIF(Entry->d_type));
#else
// Other platforms such as Solaris require a stat() to get the type.
OpenPOWER on IntegriCloud