Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | 2ff54ad7478a90bd75c91e434236a Mon Sep 17 00:00:00 2001 |
| 2 | From: makepost <makepost@firemail.cc> |
| 3 | Date: Mon, 24 Dec 2018 03:13:16 +0200 |
| 4 | Subject: [PATCH] Use st_mtim if st_mtime is macro, fix #1510 |
| 5 | |
| 6 | In POSIX.1-2008, sys_stat has a st_mtim member and a st_mtime backward |
| 7 | compatibility macro. Should help avoid hardcoding platform detection. |
| 8 | --- |
| 9 | src/disk_interface.cc | 14 ++++---------- |
| 10 | 1 file changed, 4 insertions(+), 10 deletions(-) |
| 11 | |
| 12 | diff --git a/src/disk_interface.cc b/src/disk_interface.cc |
| 13 | index d4c2fb087..dc297c449 100644 |
| 14 | --- src/disk_interface.cc |
| 15 | +++ /src/disk_interface.cc |
| 16 | @@ -202,19 +202,13 @@ TimeStamp RealDiskInterface::Stat(const string& path, string* err) const { |
| 17 | // that it doesn't exist. |
| 18 | if (st.st_mtime == 0) |
| 19 | return 1; |
| 20 | -#if defined(__APPLE__) && !defined(_POSIX_C_SOURCE) |
| 21 | +#if defined(_AIX) |
| 22 | + return (int64_t)st.st_mtime * 1000000000LL + st.st_mtime_n; |
| 23 | +#elif defined(__APPLE__) |
| 24 | return ((int64_t)st.st_mtimespec.tv_sec * 1000000000LL + |
| 25 | st.st_mtimespec.tv_nsec); |
| 26 | -#elif (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \ |
| 27 | - defined(__BIONIC__) || (defined (__SVR4) && defined (__sun)) || defined(__FreeBSD__)) |
| 28 | - // For glibc, see "Timestamp files" in the Notes of http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html |
| 29 | - // newlib, uClibc and musl follow the kernel (or Cygwin) headers and define the right macro values above. |
| 30 | - // For bsd, see https://github.com/freebsd/freebsd/blob/master/sys/sys/stat.h and similar |
| 31 | - // For bionic, C and POSIX API is always enabled. |
| 32 | - // For solaris, see https://docs.oracle.com/cd/E88353_01/html/E37841/stat-2.html. |
| 33 | +#elif defined(st_mtime) // A macro, so we're likely on modern POSIX. |
| 34 | return (int64_t)st.st_mtim.tv_sec * 1000000000LL + st.st_mtim.tv_nsec; |
| 35 | -#elif defined(_AIX) |
| 36 | - return (int64_t)st.st_mtime * 1000000000LL + st.st_mtime_n; |
| 37 | #else |
| 38 | return (int64_t)st.st_mtime * 1000000000LL + st.st_mtimensec; |
| 39 | #endif |