]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use CreateHardLinkW and CreateSymbolicLinkW directly on Vista+ builds
authorSteve Lhomme <robux4@ycbcr.xyz>
Thu, 25 May 2023 07:53:49 +0000 (09:53 +0200)
committerMartin Matuška <martin@matuska.de>
Thu, 13 Jul 2023 22:27:45 +0000 (00:27 +0200)
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

index 9bf7c3295e83199bcf7f6fde62e9132af3f2b53e..4db1675d530ad2bad5868004e3e05724aa2a585b 100644 (file)
@@ -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);