]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
preserve file modification time for Visual C++
authorPrzemyslaw Skibinski <inikep@gmail.com>
Thu, 3 Nov 2016 08:54:53 +0000 (09:54 +0100)
committerPrzemyslaw Skibinski <inikep@gmail.com>
Thu, 3 Nov 2016 08:54:53 +0000 (09:54 +0100)
programs/util.h

index 7d503d9df5091a2809b2ea3cde268f924af4a38c..fd07c348ab9ce29402aa0b0bc3024b41fc0b2974 100644 (file)
@@ -48,9 +48,15 @@ extern "C" {
 #include <stdio.h>      /* fprintf */
 #include <sys/types.h>  /* stat, utime */
 #include <sys/stat.h>   /* stat */
-#include <utime.h>      /* utime */
+#if defined(_MSC_VER)
+       #include <sys/utime.h>   /* utime */
+       #include <io.h>          /* _chmod */
+#else
+       #include <unistd.h>     /* chown, stat */
+       #include <utime.h>      /* utime */
+#endif
 #include <time.h>       /* time */
-#include <unistd.h>     /* chown, stat */
+#include <errno.h>
 #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 <dirent.h>       /* opendir, readdir */
-#  include <errno.h>
 
 UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd)
 {