Merge pull request #3515 from akallabeth/apple_time_fix

Fixed SetFileTime for mac.
This commit is contained in:
Marc-André Moreau 2016-10-05 09:21:11 -04:00 committed by GitHub
commit 1d06087b60
1 changed files with 6 additions and 22 deletions

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);