Commit 41321580 authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Use the detection idiom to handle the non-standard struct stat field name for...

Use the detection idiom to handle the non-standard struct stat field name for high-resolution mtime on Mac OS X.
parent b14baefb
......@@ -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 @@ GooFile::GooFile(int fdA)
{
struct stat statbuf;
fstat(fd, &statbuf);
modifiedTimeOnOpen = statbuf.st_mtim;
modifiedTimeOnOpen = mtim(statbuf);
}
bool GooFile::modificationTimeChangedSinceOpen() const
......@@ -695,7 +729,7 @@ bool GooFile::modificationTimeChangedSinceOpen() const
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment