summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRosen Penev <rosenp@gmail.com>2019-07-31 05:13:51 (GMT)
committerRosen Penev <rosenp@gmail.com>2019-09-10 18:29:05 (GMT)
commita55095ddd63431ecb79854f887f40b6a9fcd520c (patch)
treec6c6926d8e187d6ea2345441ecf7071868ae341e
parent64e3134b2ad5536460baa628f0f2d8f1d258dbdb (diff)
downloadlz4-a55095ddd63431ecb79854f887f40b6a9fcd520c.zip
lz4-a55095ddd63431ecb79854f887f40b6a9fcd520c.tar.gz
lz4-a55095ddd63431ecb79854f887f40b6a9fcd520c.tar.bz2
util.h: Remove deprecated utime for non-Windows
utime was deprecated in POSIX 2008.
-rw-r--r--programs/platform.h2
-rw-r--r--programs/util.h24
2 files changed, 20 insertions, 6 deletions
diff --git a/programs/platform.h b/programs/platform.h
index c0b3840..7e2cb58 100644
--- a/programs/platform.h
+++ b/programs/platform.h
@@ -86,7 +86,7 @@ extern "C" {
# else
# if defined(__linux__) || defined(__linux)
# ifndef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200112L /* use feature test macro */
+# define _POSIX_C_SOURCE 200809L /* use feature test macro */
# endif
# endif
# include <unistd.h> /* declares _POSIX_VERSION */
diff --git a/programs/util.h b/programs/util.h
index 1dd515c..8e361ca 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -37,12 +37,17 @@ extern "C" {
#include <assert.h>
#include <sys/types.h> /* stat, utime */
#include <sys/stat.h> /* stat */
-#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> /* for utimensat */
+# endif
#endif
#include <time.h> /* time */
#include <limits.h> /* INT_MAX */
@@ -287,14 +292,23 @@ UTIL_STATIC int UTIL_isRegFile(const char* infilename);
UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
{
int res = 0;
- struct utimbuf timebuf;
if (!UTIL_isRegFile(filename))
return -1;
- timebuf.actime = time(NULL);
- timebuf.modtime = statbuf->st_mtime;
- res += utime(filename, &timebuf); /* set access and modification times */
+ {
+#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
+ struct utimbuf timebuf;
+ timebuf.actime = time(NULL);
+ timebuf.modtime = statbuf->st_mtime;
+ res += utime(filename, &timebuf); /* set access and modification times */
+#else
+ struct timespec timebuf[2] = {};
+ 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 */