Skip to content

Commit 567815d

Browse files
committed
Use st_mtim if st_mtime is macro, fix #1510
In POSIX.1-2008, sys_stat has a st_mtim member and a st_mtime backward compatibility macro. Should help avoid hardcoding platform detection.
1 parent 6e02ebc commit 567815d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/disk_interface.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,13 @@ TimeStamp RealDiskInterface::Stat(const string& path, string* err) const {
202202
// that it doesn't exist.
203203
if (st.st_mtime == 0)
204204
return 1;
205-
#if defined(__APPLE__) && !defined(_POSIX_C_SOURCE)
205+
#if defined(_AIX)
206+
return (int64_t)st.st_mtime * 1000000000LL + st.st_mtime_n;
207+
#elif defined(__APPLE__)
206208
return ((int64_t)st.st_mtimespec.tv_sec * 1000000000LL +
207209
st.st_mtimespec.tv_nsec);
208-
#elif (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \
209-
defined(__BIONIC__) || (defined (__SVR4) && defined (__sun)) || defined(__FreeBSD__))
210-
// For glibc, see "Timestamp files" in the Notes of http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html
211-
// newlib, uClibc and musl follow the kernel (or Cygwin) headers and define the right macro values above.
212-
// For bsd, see https://github.com/freebsd/freebsd/blob/master/sys/sys/stat.h and similar
213-
// For bionic, C and POSIX API is always enabled.
214-
// For solaris, see https://docs.oracle.com/cd/E88353_01/html/E37841/stat-2.html.
210+
#elif defined(st_mtime) // A macro, so we're likely on modern POSIX.
215211
return (int64_t)st.st_mtim.tv_sec * 1000000000LL + st.st_mtim.tv_nsec;
216-
#elif defined(_AIX)
217-
return (int64_t)st.st_mtime * 1000000000LL + st.st_mtime_n;
218212
#else
219213
return (int64_t)st.st_mtime * 1000000000LL + st.st_mtimensec;
220214
#endif

0 commit comments

Comments
 (0)