Use the detection idiom to handle the non-standard struct stat field name for high-resolution mtime on Mac OS X.
diff --git a/goo/gfile.cc b/goo/gfile.cc
index e4c9b9f..218882d 100644
--- a/goo/gfile.cc
+++ b/goo/gfile.cc
@@ -21,7 +21,7 @@
// Copyright (C) 2008, 2010, 2012, 2013 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2009, 2012, 2014, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
-// Copyright (C) 2013 Adam Reichold <adamreichold@myopera.com>
+// Copyright (C) 2013, 2018 Adam Reichold <adamreichold@myopera.com>
// Copyright (C) 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Peter Breitenlohner <peb@mppmu.mpg.de>
// Copyright (C) 2013, 2017 Thomas Freitag <Thomas.Freitag@alfa.de>
@@ -65,6 +65,40 @@
#define PATH_MAX 1024
#endif
+namespace {
+
+template< typename... >
+struct void_type
+{
+ using type = void;
+};
+
+template< typename... Args >
+using void_t = typename void_type< Args... >::type;
+
+template< typename Stat, typename = void_t<> >
+struct StatMtim
+{
+ static const struct timespec& value(const Stat& stbuf) {
+ return stbuf.st_mtim;
+ }
+};
+
+// Mac OS X uses a different field name than POSIX and this detects it.
+template< typename Stat >
+struct StatMtim< Stat, void_t< decltype ( Stat::st_mtimespec ) > >
+{
+ static const struct timespec& value(const Stat& stbuf) {
+ return stbuf.st_mtimespec;
+ }
+};
+
+inline const struct timespec& mtim(const struct stat& stbuf) {
+ return StatMtim< struct stat >::value(stbuf);
+}
+
+}
+
//------------------------------------------------------------------------
GooString *getCurrentDir() {
@@ -687,7 +721,7 @@
{
struct stat statbuf;
fstat(fd, &statbuf);
- modifiedTimeOnOpen = statbuf.st_mtim;
+ modifiedTimeOnOpen = mtim(statbuf);
}
bool GooFile::modificationTimeChangedSinceOpen() const
@@ -695,7 +729,7 @@
struct stat statbuf;
fstat(fd, &statbuf);
- return modifiedTimeOnOpen.tv_sec != statbuf.st_mtim.tv_sec || modifiedTimeOnOpen.tv_nsec != statbuf.st_mtim.tv_nsec;
+ return modifiedTimeOnOpen.tv_sec != mtim(statbuf).tv_sec || modifiedTimeOnOpen.tv_nsec != mtim(statbuf).tv_nsec;
}
#endif // _WIN32