1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-29 11:21:22 +03:00

preserve file modification time for Visual C++

This commit is contained in:
Przemyslaw Skibinski
2016-11-03 09:54:53 +01:00
parent fcf22e3473
commit b40884f43d

View File

@ -48,9 +48,15 @@ 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 */ #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 <time.h> /* time */
#include <unistd.h> /* chown, stat */ #include <errno.h>
#include "mem.h" /* U32, U64 */ #include "mem.h" /* U32, U64 */
@ -146,7 +152,8 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond)
* File functions * File functions
******************************************/ ******************************************/
#if defined(_MSC_VER) #if defined(_MSC_VER)
typedef struct _stat64 stat_t; #define chmod _chmod
typedef struct _stat64 stat_t;
#else #else
typedef struct stat stat_t; typedef struct stat stat_t;
#endif #endif
@ -157,16 +164,16 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
int res = 0; int res = 0;
struct utimbuf timebuf; struct utimbuf timebuf;
timebuf.actime = time(NULL);
timebuf.modtime = statbuf->st_mtime;
res += utime(filename, &timebuf); /* set access and modification times */
#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 */
#endif #endif
res += chmod(filename, statbuf->st_mode & 07777); /* Copy file permissions */ 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; errno = 0;
return -res; /* number of errors is returned */ 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 */ ((defined(__unix__) || defined(__unix) || defined(__midipix__)) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) /* snprintf, opendir */
# define UTIL_HAS_CREATEFILELIST # define UTIL_HAS_CREATEFILELIST
# include <dirent.h> /* opendir, readdir */ # include <dirent.h> /* opendir, readdir */
# include <errno.h>
UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd) UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd)
{ {