Merge pull request #1920 from felixhandte/fix-mtim-again

Use statbuf->st_mtim Again
This commit is contained in:
Felix Handte 2020-01-03 16:07:16 -05:00 committed by GitHub
commit 68160372be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 8 deletions

View File

@ -137,6 +137,13 @@ matrix:
- make arminstall
- make armfuzz
# Introduced to check compat with old toolchains, to prevent e.g. #1872
- name: ARM Build Test (on Trusty)
dist: trusty
script:
- make arminstall
- make armbuild
- name: Qemu PPC + Fuzz Test # ~13mn
dist: trusty # it seems ppc cross-compilation fails on "current"
script:

View File

@ -109,6 +109,15 @@ extern "C" {
#endif /* PLATFORM_POSIX_VERSION */
#if PLATFORM_POSIX_VERSION > 1
/* glibc < 2.26 may not expose struct timespec def without this.
* See issue #1920. */
# ifndef _ATFILE_SOURCE
# define _ATFILE_SOURCE
# endif
#endif
/*-*********************************************
* Detect if isatty() and fileno() are available
************************************************/

View File

@ -145,20 +145,24 @@ int UTIL_setFileStat(const char *filename, stat_t *statbuf)
return -1;
/* set access and modification times */
#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
/* We check that st_mtime is a macro here in order to give us confidence
* that struct stat has a struct timespec st_mtim member. We need this
* check because there are some platforms that claim to be POSIX 2008
* compliant but which do not have st_mtim... */
#if (PLATFORM_POSIX_VERSION >= 200809L) && defined(st_mtime)
{
/* (atime, mtime) */
struct timespec timebuf[2] = { {0, UTIME_NOW} };
timebuf[1] = statbuf->st_mtim;
res += utimensat(AT_FDCWD, filename, timebuf, 0);
}
#else
{
struct utimbuf timebuf;
timebuf.actime = time(NULL);
timebuf.modtime = statbuf->st_mtime;
res += utime(filename, &timebuf);
}
#else
{
/* (atime, mtime) */
struct timespec timebuf[2] = { {0, UTIME_NOW} };
timebuf[1].tv_sec = statbuf->st_mtime;
res += utimensat(AT_FDCWD, filename, timebuf, 0);
}
#endif
#if !defined(_WIN32)