[PATCH] D54883: [Support/FileSystem] Use st_atimespec only when __APPLE__ is defined

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 25 19:24:39 PST 2018


MaskRay created this revision.
MaskRay added reviewers: akyrtzi, labath, zturner, aaron.ballman, kristina.
Herald added subscribers: llvm-commits, krytarowski, mgorny, emaste.

st_atim is required by POSIX 2008 and has very good support across POSIX platforms (glibc 2.12, FreeBSD 9, some very old versions of OpenBSD, NetBSD illumos, ...). We can simplify the code by fallbacking to st_atimespec only when __APPLE__ is defined.


Repository:
  rL LLVM

https://reviews.llvm.org/D54883

Files:
  cmake/config-ix.cmake
  include/llvm/Config/config.h.cmake
  lib/Support/Unix/Path.inc


Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -592,14 +592,12 @@
   }
 
   uint32_t atime_nsec, mtime_nsec;
-#if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
+#ifdef __APPLE__
   atime_nsec = Status.st_atimespec.tv_nsec;
   mtime_nsec = Status.st_mtimespec.tv_nsec;
-#elif defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
+#else
   atime_nsec = Status.st_atim.tv_nsec;
   mtime_nsec = Status.st_mtim.tv_nsec;
-#else
-  atime_nsec = mtime_nsec = 0;
 #endif
 
   perms Perms = static_cast<perms>(Status.st_mode) & all_perms;
Index: include/llvm/Config/config.h.cmake
===================================================================
--- include/llvm/Config/config.h.cmake
+++ include/llvm/Config/config.h.cmake
@@ -208,12 +208,6 @@
 /* Define to 1 if you have the <sys/time.h> header file. */
 #cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H}
 
-/* Define to 1 if stat struct has st_mtimespec member .*/
-#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC}
-
-/* Define to 1 if stat struct has st_mtim member. */
-#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC}
-
 /* Define to 1 if you have the <sys/types.h> header file. */
 #cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
 
Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -7,7 +7,6 @@
 include(CheckLibraryExists)
 include(CheckSymbolExists)
 include(CheckFunctionExists)
-include(CheckStructHasMember)
 include(CheckCCompilerFlag)
 
 include(CheckCompilerVersion)
@@ -249,11 +248,6 @@
   endif()
 endif()
 
-CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec
-    "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
-CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec
-    "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
-
 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
 if( LLVM_USING_GLIBC )
   add_definitions( -D_GNU_SOURCE )


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54883.175190.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181126/963a927a/attachment.bin>


More information about the llvm-commits mailing list