From 86641b9ab5c1020dbe1ca089bd002fc3e85841a5 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 25 May 2023 09:53:49 +0200 Subject: [PATCH] Use CreateHardLinkW and CreateSymbolicLinkW directly on Vista+ builds No need to load the kernel library manually. It's always available. It's not possible to load it in Universal Windows Platform (UWP) builds anyway. No need to load the kernel library manually. It's always available. It's not possible to load it in Universal Windows Platform (UWP) builds anyway. --- libarchive/archive_write_disk_windows.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libarchive/archive_write_disk_windows.c b/libarchive/archive_write_disk_windows.c index 9bf7c3295..4db1675d5 100644 --- a/libarchive/archive_write_disk_windows.c +++ b/libarchive/archive_write_disk_windows.c @@ -559,6 +559,7 @@ la_mktemp(struct archive_write_disk *a) return (fd); } +#if _WIN32_WINNT < _WIN32_WINNT_VISTA static void * la_GetFunctionKernel32(const char *name) { @@ -574,18 +575,24 @@ la_GetFunctionKernel32(const char *name) } return (void *)GetProcAddress(lib, name); } +#endif static int la_CreateHardLinkW(wchar_t *linkname, wchar_t *target) { static BOOLEAN (WINAPI *f)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES); - static int set; BOOL ret; +#if _WIN32_WINNT < _WIN32_WINNT_XP + static int set; +/* CreateHardLinkW is available since XP and always loaded */ if (!set) { set = 1; f = la_GetFunctionKernel32("CreateHardLinkW"); } +#else + f = CreateHardLinkW; +#endif if (!f) { errno = ENOTSUP; return (0); @@ -624,7 +631,6 @@ static int la_CreateSymbolicLinkW(const wchar_t *linkname, const wchar_t *target, int linktype) { static BOOLEAN (WINAPI *f)(LPCWSTR, LPCWSTR, DWORD); - static int set; wchar_t *ttarget, *p; size_t len; DWORD attrs = 0; @@ -632,10 +638,16 @@ la_CreateSymbolicLinkW(const wchar_t *linkname, const wchar_t *target, DWORD newflags = 0; BOOL ret = 0; +#if _WIN32_WINNT < _WIN32_WINNT_VISTA +/* CreateSymbolicLinkW is available since Vista and always loaded */ + static int set; if (!set) { set = 1; f = la_GetFunctionKernel32("CreateSymbolicLinkW"); } +#else + f = CreateSymbolicLinkW; +#endif if (!f) return (0); -- 2.47.2