From b4ec4028597c06bbdbf283b4a5f5957dd2c1b809 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Thu, 7 Nov 2019 16:24:34 +0100 Subject: [PATCH] ntdll: Work around futimens weak linking problem in set_file_times. Newer XCode versions are weak linking to futimens function. Because of that Wine will crash trying to execute the function on Mac OS <= 10.12. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/ntdll/file.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index 655dcb2eafe..dd6d1341b01 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -1907,10 +1907,9 @@ static int futimens( int fd, const struct timespec spec[2] ) #define UTIME_OMIT ((1 << 30) - 2) #endif -static NTSTATUS set_file_times( int fd, const LARGE_INTEGER *mtime, const LARGE_INTEGER *atime ) +static BOOL set_file_times_precise( int fd, const LARGE_INTEGER *mtime, + const LARGE_INTEGER *atime, NTSTATUS *status ) { - NTSTATUS status = STATUS_SUCCESS; - #ifdef HAVE_FUTIMENS struct timespec tv[2]; @@ -1926,12 +1925,29 @@ static NTSTATUS set_file_times( int fd, const LARGE_INTEGER *mtime, const LARGE_ tv[1].tv_sec = mtime->QuadPart / 10000000 - SECS_1601_TO_1970; tv[1].tv_nsec = (mtime->QuadPart % 10000000) * 100; } - if (futimens( fd, tv ) == -1) status = FILE_GetNtStatus(); +#ifdef __APPLE__ + if (!&futimens) return FALSE; +#endif + if (futimens( fd, tv ) == -1) *status = FILE_GetNtStatus(); + else *status = STATUS_SUCCESS; + return TRUE; +#else + return FALSE; +#endif +} -#elif defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT) +static NTSTATUS set_file_times( int fd, const LARGE_INTEGER *mtime, const LARGE_INTEGER *atime ) +{ + NTSTATUS status = STATUS_SUCCESS; +#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT) struct timeval tv[2]; struct stat st; +#endif + if (set_file_times_precise( fd, mtime, atime, &status )) + return status; + +#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT) if (!atime->QuadPart || !mtime->QuadPart) {