From efdfc1d84ce42a177ffea92571d00908f6d8bd48 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 11 Dec 2024 10:25:41 -0500 Subject: Avoid _get_osfhandle with clang on Windows This function crashes when called in a clang build, I'm not sure why. File locking in general isn't a realiable enough facility, and this API weirdly uses FILE* unlike anything else, adding it was probably a mistake. --- src/win32/filesystem_win32.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/win32/filesystem_win32.c b/src/win32/filesystem_win32.c index 24ba427..fa40cde 100644 --- a/src/win32/filesystem_win32.c +++ b/src/win32/filesystem_win32.c @@ -222,6 +222,12 @@ zix_dir_for_each(const char* const path, ZixStatus zix_file_lock(FILE* const file, const ZixFileLockMode mode) { +#ifdef __clang__ + (void)file; + (void)mode; + return ZIX_STATUS_NOT_SUPPORTED; +#else + HANDLE handle = (HANDLE)_get_osfhandle(fileno(file)); OVERLAPPED overlapped = {0}; @@ -231,18 +237,24 @@ zix_file_lock(FILE* const file, const ZixFileLockMode mode) return zix_windows_status( LockFileEx(handle, flags, 0, UINT32_MAX, UINT32_MAX, &overlapped)); +#endif } ZixStatus zix_file_unlock(FILE* const file, const ZixFileLockMode mode) { (void)mode; +#ifdef __clang__ + (void)file; + return ZIX_STATUS_NOT_SUPPORTED; +#else HANDLE handle = (HANDLE)_get_osfhandle(fileno(file)); OVERLAPPED overlapped = {0}; return zix_windows_status( UnlockFileEx(handle, 0, UINT32_MAX, UINT32_MAX, &overlapped)); +#endif } #if USE_GETFINALPATHNAMEBYHANDLE && USE_CREATEFILE2 -- cgit v1.2.1