diff --git a/CMakeLists.txt b/CMakeLists.txt index 808cfb0..4bcf0e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,10 @@ include(CheckIncludeFileCXX) check_include_file_cxx(endian.h HAVE_ENDIAN_H) check_include_file_cxx(sys/endian.h HAVE_SYS_ENDIAN_H) +include(CheckStructHasMember) +check_struct_has_member("struct stat" st_mtim sys/stat.h HAVE_STAT_ST_MTIM LANGUAGE CXX) +check_struct_has_member("struct stat" st_mtimespec sys/stat.h HAVE_STAT_ST_MTIMESPEC LANGUAGE CXX) + configure_file(src/config.h.in config.h @ONLY) include_directories(BEFORE src "${CMAKE_BINARY_DIR}" ${OGG_INCLUDE_DIRS} ${Iconv_INCLUDE_DIRS}) diff --git a/src/config.h.in b/src/config.h.in index 7699db8..8793e25 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -3,3 +3,5 @@ #cmakedefine HAVE_ENDIAN_H @HAVE_ENDIAN_H@ #cmakedefine HAVE_SYS_ENDIAN_H @HAVE_SYS_ENDIAN_H@ +#cmakedefine HAVE_STAT_ST_MTIM @HAVE_STAT_ST_MTIM@ +#cmakedefine HAVE_STAT_ST_MTIMESPEC @HAVE_STAT_ST_MTIMESPEC@ diff --git a/src/system.cc b/src/system.cc index 7357a03..5420e74 100644 --- a/src/system.cc +++ b/src/system.cc @@ -179,6 +179,13 @@ ot::status ot::get_file_timestamp(const char* path, timespec& mtime) struct stat st; if (stat(path, &st) == -1) return {st::standard_error, path + ": stat error: "s + strerror(errno)}; - mtime = st.st_mtim; // more precise than st_mtime +#if defined(HAVE_STAT_ST_MTIM) + mtime = st.st_mtim; +#elif defined(HAVE_STAT_ST_MTIMESPEC) + mtime = st.st_mtimespec; +#else + mtime.tv_sec = st.st_mtime; + mtime.tv_nsec = st.st_mtimensec; +#endif return st::ok; }