Fixed SetFileTime for mac.

This commit is contained in:
Armin Novak 2016-09-27 13:28:39 +02:00
parent 3a9cc2cac8
commit 3eb136d167

View File

@ -361,7 +361,7 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
struct stat buf;
#endif
/* OpenBSD, NetBSD and DragonflyBSD support POSIX futimens */
#if defined(ANDROID) || defined(__FreeBSD__)
#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__)
struct timeval timevals[2];
#else
struct timespec times[2]; /* last access, last modification */
@ -379,14 +379,7 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
#endif
if (!lpLastAccessTime)
{
#if defined(__APPLE__)
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
times[0] = buf.st_atimespec;
#else
times[0].tv_sec = buf.st_atime;
times[0].tv_nsec = buf.st_atimensec;
#endif
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__APPLE__)
timevals[0].tv_sec = buf.st_atime;
#ifdef _POSIX_SOURCE
TIMESPEC_TO_TIMEVAL(&timevals[0], &buf.st_atim);
@ -408,7 +401,7 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
tmp -= EPOCH_DIFF;
tmp /= 10ULL;
#if defined(ANDROID) || defined(__FreeBSD__)
#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__)
tmp /= 10000ULL;
timevals[0].tv_sec = tmp / 10000ULL;
@ -420,14 +413,7 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
}
if (!lpLastWriteTime)
{
#ifdef __APPLE__
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
times[1] = buf.st_mtimespec;
#else
times[1].tv_sec = buf.st_mtime;
times[1].tv_nsec = buf.st_mtimensec;
#endif
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__APPLE__)
timevals[1].tv_sec = buf.st_mtime;
#ifdef _POSIX_SOURCE
TIMESPEC_TO_TIMEVAL(&timevals[1], &buf.st_mtim);
@ -449,7 +435,7 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
tmp -= EPOCH_DIFF;
tmp /= 10ULL;
#if defined(ANDROID) || defined(__FreeBSD__)
#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__)
tmp /= 10000ULL;
timevals[1].tv_sec = tmp / 10000ULL;
@ -461,9 +447,7 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
}
// TODO: Creation time can not be handled!
#ifdef __APPLE__
rc = futimes(fileno(pFile->fp), times);
#elif defined(ANDROID) || defined(__FreeBSD__)
#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__)
rc = utimes(pFile->lpFileName, timevals);
#else
rc = futimens(fileno(pFile->fp), times);