# if defined(__linux__) || defined(__linux)
# ifndef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200112L /* feature test macro : https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html */
+# define _POSIX_C_SOURCE 200809L /* feature test macro : https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html */
# endif
# endif
# include <unistd.h> /* declares _POSIX_VERSION */
/*-****************************************
* Dependencies
******************************************/
-#include <sys/types.h> /* utime */
-#if defined(_MSC_VER)
-# include <sys/utime.h> /* utime */
-#else
-# include <utime.h> /* utime */
-#endif
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
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;
+#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 */
+#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 */
+#endif
#if !defined(_WIN32)
res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */
#include <stdio.h> /* fprintf */
#include <sys/types.h> /* stat, utime */
#include <sys/stat.h> /* stat, chmod */
-#if defined(_MSC_VER)
+#if defined(_WIN32)
# include <sys/utime.h> /* utime */
# include <io.h> /* _chmod */
#else
# include <unistd.h> /* chown, stat */
+#if PLATFORM_POSIX_VERSION < 200809L
# include <utime.h> /* utime */
+#else
+# include <fcntl.h> /* AT_FDCWD */
+# include <sys/stat.h> /* utimensat */
+#endif
#endif
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
#include "mem.h" /* U32, U64 */