From b40884f43d316f7e2acef20cd7d53b752e31c8e8 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Thu, 3 Nov 2016 09:54:53 +0100 Subject: [PATCH] preserve file modification time for Visual C++ --- programs/util.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/programs/util.h b/programs/util.h index 7d503d9df..fd07c348a 100644 --- a/programs/util.h +++ b/programs/util.h @@ -48,9 +48,15 @@ extern "C" { #include /* fprintf */ #include /* stat, utime */ #include /* stat */ -#include /* utime */ +#if defined(_MSC_VER) + #include /* utime */ + #include /* _chmod */ +#else + #include /* chown, stat */ + #include /* utime */ +#endif #include /* time */ -#include /* chown, stat */ +#include #include "mem.h" /* U32, U64 */ @@ -146,7 +152,8 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond) * File functions ******************************************/ #if defined(_MSC_VER) - typedef struct _stat64 stat_t; + #define chmod _chmod + typedef struct _stat64 stat_t; #else typedef struct stat stat_t; #endif @@ -157,16 +164,16 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) int res = 0; struct utimbuf timebuf; + timebuf.actime = time(NULL); + timebuf.modtime = statbuf->st_mtime; + res += utime(filename, &timebuf); /* set access and modification times */ + #if !defined(_WIN32) res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */ #endif res += chmod(filename, statbuf->st_mode & 07777); /* Copy file permissions */ - timebuf.actime = time(NULL); - timebuf.modtime = statbuf->st_mtime; - res += utime(filename, &timebuf); /* set access and modification times */ - errno = 0; return -res; /* number of errors is returned */ } @@ -322,7 +329,6 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_ ((defined(__unix__) || defined(__unix) || defined(__midipix__)) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) /* snprintf, opendir */ # define UTIL_HAS_CREATEFILELIST # include /* opendir, readdir */ -# include UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd) {