Merge pull request #1783 from felixhandte/mtime-nsec

Set Mod Time Nanoseconds
This commit is contained in:
Felix Handte 2019-09-17 13:30:21 -04:00 committed by GitHub
commit dd2838eeb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,23 +54,24 @@ int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
int UTIL_setFileStat(const char *filename, stat_t *statbuf)
{
int res = 0;
#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
struct utimbuf timebuf;
#else
struct timespec timebuf[2] = {};
#endif
if (!UTIL_isRegularFile(filename))
return -1;
/* set access and modification times */
#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
timebuf.actime = time(NULL);
timebuf.modtime = statbuf->st_mtime;
res += utime(filename, &timebuf); /* set access and modification times */
{
struct utimbuf timebuf;
timebuf.actime = time(NULL);
timebuf.modtime = statbuf->st_mtime;
res += utime(filename, &timebuf);
}
#else
timebuf[0].tv_nsec = UTIME_NOW;
timebuf[1].tv_sec = statbuf->st_mtime;
res += utimensat(AT_FDCWD, filename, timebuf, 0); /* set access and modification times */
{
/* (atime, mtime) */
struct timespec timebuf[2] = { {0, UTIME_NOW}, statbuf->st_mtim };
res += utimensat(AT_FDCWD, filename, timebuf, 0);
}
#endif
#if !defined(_WIN32)