]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstd: Don't use utime on Linux 1708/head
authorRosen Penev <rosenp@gmail.com>
Wed, 31 Jul 2019 00:17:07 +0000 (17:17 -0700)
committerRosen Penev <rosenp@gmail.com>
Wed, 31 Jul 2019 19:29:13 +0000 (12:29 -0700)
utime is deprecated by POSIX 2008 and optionally not available with
uClibc-ng.

Got rid of a few useless headers in timefn.h.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
programs/platform.h
programs/timefn.h
programs/util.c
programs/util.h

index 38ded872743e4b53d46ca0c4af78af863457111c..5934e59cf12dbabf47ed3e6772aa34363a15ee6a 100644 (file)
@@ -92,7 +92,7 @@ extern "C" {
 
 #    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 */
index d1ddd31b1c0003b582b1c28e6dfe0b1ddd239ad9..2db3765b93088e8fbba9f84e4728829b6dc861ec 100644 (file)
@@ -19,12 +19,6 @@ extern "C" {
 /*-****************************************
 *  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 */
 
 
index fb77d17839281413e26b4b7f3a016e7662455cef..3a2c0a9d78b4a7792dcdc389548a395254db1687 100644 (file)
@@ -54,14 +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;
 
+#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 */
index d6e5bb550ec7e59da23d7eedd5eefe7375b61020..0080b63c7a152b8eeb7ae7df5b7d0d18852b6c82 100644 (file)
@@ -25,12 +25,17 @@ extern "C" {
 #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 */