diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/win32/filesystem_win32.c | 61 | ||||
-rw-r--r-- | src/zix_config.h | 35 |
2 files changed, 75 insertions, 21 deletions
diff --git a/src/win32/filesystem_win32.c b/src/win32/filesystem_win32.c index c88b1ff..196818b 100644 --- a/src/win32/filesystem_win32.c +++ b/src/win32/filesystem_win32.c @@ -248,6 +248,49 @@ zix_file_unlock(FILE* const file, const ZixFileLockMode mode) UnlockFileEx(handle, 0, UINT32_MAX, UINT32_MAX, &overlapped)); } +#if USE_GETFINALPATHNAMEBYHANDLE && USE_CREATEFILE2 + +static HANDLE +open_attribute_handle(const char* const path) +{ + wchar_t* const wpath = zix_utf8_to_wchar(NULL, path); + + CREATEFILE2_EXTENDED_PARAMETERS params = { + sizeof(CREATEFILE2_EXTENDED_PARAMETERS), + 0U, + FILE_FLAG_BACKUP_SEMANTICS, + 0U, + NULL, + NULL}; + + const HANDLE handle = + CreateFile2(wpath, FILE_READ_ATTRIBUTES, 0U, OPEN_EXISTING, ¶ms); + + zix_free(NULL, wpath); + return handle; +} + +#elif USE_GETFINALPATHNAMEBYHANDLE + +static HANDLE +open_attribute_handle(const char* const path) +{ + ArgPathChar* const wpath = arg_path_new(NULL, path); + + const HANDLE handle = CreateFile(wpath, + FILE_READ_ATTRIBUTES, + 0U, + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL); + + arg_path_free(NULL, wpath); + return handle; +} + +#endif + char* zix_canonical_path(ZixAllocator* const allocator, const char* const path) { @@ -255,20 +298,10 @@ zix_canonical_path(ZixAllocator* const allocator, const char* const path) return NULL; } - ArgPathChar* const wpath = arg_path_new(allocator, path); - #if USE_GETFINALPATHNAMEBYHANDLE // Vista+ - const HANDLE h = - CreateFile(wpath, - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, - NULL); - - TCHAR* final = NULL; + const HANDLE h = open_attribute_handle(path); + TCHAR* final = NULL; if (h != INVALID_HANDLE_VALUE) { const DWORD flags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS; const DWORD length = GetFinalPathNameByHandle(h, NULL, 0U, flags); @@ -281,12 +314,12 @@ zix_canonical_path(ZixAllocator* const allocator, const char* const path) } CloseHandle(h); - arg_path_free(allocator, wpath); return path_result(allocator, final); #else // Fall back to "full path iff it exists" for older Windows - TCHAR* full = NULL; + ArgPathChar* const wpath = arg_path_new(allocator, path); + TCHAR* full = NULL; if (GetFileAttributes(wpath) != INVALID_FILE_ATTRIBUTES) { const DWORD length = GetFullPathName(wpath, 0U, NULL, NULL); if (length) { diff --git a/src/zix_config.h b/src/zix_config.h index 6bbc92b..abcd11e 100644 --- a/src/zix_config.h +++ b/src/zix_config.h @@ -55,6 +55,13 @@ # define ZIX_POSIX_VERSION 0 # endif +// Define ZIX_WINAPI_UWP to 1 (if this is a sandboxed UWP app) or 0 +# if defined(WINAPI_FAMILY) && WINAPI_FAMILY < 10 +# define ZIX_WINAPI_UWP 1 +# else +# define ZIX_WINAPI_UWP 0 +# endif + // POSIX.1-2001: clock_gettime() # ifndef HAVE_CLOCK_GETTIME # if ZIX_POSIX_VERSION >= 200112L @@ -78,16 +85,24 @@ # endif # endif -// Windows XP: CreateHardLink() +// Windows 8 (Desktop, UWP): CreateFile2() +# ifndef HAVE_CREATEFILE2 +# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 && !defined(__MINGW32__) +# define HAVE_CREATEFILE2 1 +# endif +# endif + +// Windows XP (Desktop): CreateHardLink() # ifndef HAVE_CREATEHARDLINK -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0501 +# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0501 && !ZIX_WINAPI_UWP # define HAVE_CREATEHARDLINK 1 # endif # endif -// Windows Vista: CreateSymbolicLink() +// Windows Vista (Desktop): CreateSymbolicLink() # ifndef HAVE_CREATESYMBOLICLINK -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && !defined(__MINGW32__) +# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && \ + !defined(__MINGW32__) && !ZIX_WINAPI_UWP # define HAVE_CREATESYMBOLICLINK 1 # endif # endif @@ -106,7 +121,7 @@ # endif # endif -// Windows Vista: GetFinalPathNameByHandle() +// Windows Vista (Desktop, UWP): GetFinalPathNameByHandle() # ifndef HAVE_GETFINALPATHNAMEBYHANDLE # if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 # define HAVE_GETFINALPATHNAMEBYHANDLE 1 @@ -162,9 +177,9 @@ # endif # endif -// Windows XP: VirtualLock +// Windows XP (Desktop): VirtualLock # ifndef HAVE_VIRTUALLOCK -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0501 +# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0501 && !ZIX_WINAPI_UWP # define HAVE_VIRTUALLOCK 1 # endif # endif @@ -197,6 +212,12 @@ # define USE_COPY_FILE_RANGE 0 #endif +#if defined(HAVE_CREATEFILE2) && HAVE_CREATEFILE2 +# define USE_CREATEFILE2 1 +#else +# define USE_CREATEFILE2 0 +#endif + #if defined(HAVE_CREATEHARDLINK) && HAVE_CREATEHARDLINK # define USE_CREATEHARDLINK 1 #else |