zstd: Don't use utime on Linux

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>
This commit is contained in:
Rosen Penev 2019-07-30 17:17:07 -07:00
parent d95ac34202
commit 41e90653fe
No known key found for this signature in database
GPG Key ID: 36D31CFA845F0E3B
4 changed files with 17 additions and 8 deletions

View File

@ -92,7 +92,7 @@ extern "C" {
# if defined(__linux__) || defined(__linux) # if defined(__linux__) || defined(__linux)
# ifndef _POSIX_C_SOURCE # 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
# endif # endif
# include <unistd.h> /* declares _POSIX_VERSION */ # include <unistd.h> /* declares _POSIX_VERSION */

View File

@ -19,12 +19,6 @@ extern "C" {
/*-**************************************** /*-****************************************
* Dependencies * 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 */ #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */

View File

@ -54,14 +54,24 @@ int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
int UTIL_setFileStat(const char *filename, stat_t *statbuf) int UTIL_setFileStat(const char *filename, stat_t *statbuf)
{ {
int res = 0; int res = 0;
#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
struct utimbuf timebuf; struct utimbuf timebuf;
#else
struct timespec timebuf[2] = {};
#endif
if (!UTIL_isRegularFile(filename)) if (!UTIL_isRegularFile(filename))
return -1; return -1;
#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
timebuf.actime = time(NULL); timebuf.actime = time(NULL);
timebuf.modtime = statbuf->st_mtime; timebuf.modtime = statbuf->st_mtime;
res += utime(filename, &timebuf); /* set access and modification times */ 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) #if !defined(_WIN32)
res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */ res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */

View File

@ -25,12 +25,17 @@ extern "C" {
#include <stdio.h> /* fprintf */ #include <stdio.h> /* fprintf */
#include <sys/types.h> /* stat, utime */ #include <sys/types.h> /* stat, utime */
#include <sys/stat.h> /* stat, chmod */ #include <sys/stat.h> /* stat, chmod */
#if defined(_MSC_VER) #if defined(_WIN32)
# include <sys/utime.h> /* utime */ # include <sys/utime.h> /* utime */
# include <io.h> /* _chmod */ # include <io.h> /* _chmod */
#else #else
# include <unistd.h> /* chown, stat */ # include <unistd.h> /* chown, stat */
#if PLATFORM_POSIX_VERSION < 200809L
# include <utime.h> /* utime */ # include <utime.h> /* utime */
#else
# include <fcntl.h> /* AT_FDCWD */
# include <sys/stat.h> /* utimensat */
#endif
#endif #endif
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */ #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
#include "mem.h" /* U32, U64 */ #include "mem.h" /* U32, U64 */