From: Tim Kientzle Date: Sat, 5 Sep 2009 02:41:09 +0000 (-0400) Subject: Probe for CreateHardLinkW and use it only if it's found. X-Git-Tag: v2.8.0~385 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3407cbf6a0ff6e6f05b2228a1f934b4223871e81;p=thirdparty%2Flibarchive.git Probe for CreateHardLinkW and use it only if it's found. (Needed for MinGW, which doesn't have new enough Windows headers to compile calls to CreateHardLinkW.) SVN-Revision: 1423 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fa7d5b28d..11f511dc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -337,6 +337,7 @@ CHECK_FUNCTION_EXISTS(SHA512_Init HAVE_SHA512) # Check functions # CHECK_SYMBOL_EXISTS(CreateHardLinkA "windows.h" HAVE_CREATEHARDLINKA) +CHECK_SYMBOL_EXISTS(CreateHardLinkW "windows.h" HAVE_CREATEHARDLINKW) CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN) CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 0347d8959..416ffc18a 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -57,11 +57,11 @@ /* Define to 1 if you have the `chroot' function. */ #cmakedefine HAVE_CHROOT 1 -/* Define to 1 if you have the `CreateSymbolicLink function. */ -#cmakedefine HAVE_CREATESYMBOLICLINK 1 +/* Define to 1 if you have the `CreateHardLinkA' function. */ +#cmakedefine HAVE_CREATEHARDLINKA 1 -/* Define to 1 if you have the `CreateHardLink function. */ -#cmakedefine HAVE_CREATEHARDLINK 1 +/* Define to 1 if you have the `CreateHardLinkW' function. */ +#cmakedefine HAVE_CREATEHARDLINKW 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_CTYPE_H 1 diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index 2e5e8578a..cd3a06733 100644 --- a/libarchive/archive_windows.c +++ b/libarchive/archive_windows.c @@ -218,6 +218,10 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, return (handle); } +#if HAVE_CREATEHARDLINKW +/* Check that path1 and path2 can be hard-linked by each other. + * Both arguments must be made by permissive_name function. + */ static size_t wequallen(const wchar_t *s1, const wchar_t *s2) { @@ -229,9 +233,6 @@ wequallen(const wchar_t *s1, const wchar_t *s2) return (i); } -/* Check that path1 and path2 can be hard-linked by each other. - * Both arguments must be made by permissive_name function. - */ static int canHardLinkW(const wchar_t *path1, const wchar_t *path2) { @@ -297,6 +298,7 @@ canHardLinkW(const wchar_t *path1, const wchar_t *path2) else return (0); } +#endif /* Make a link to src called dst. */ static int @@ -328,9 +330,11 @@ __link(const char *src, const char *dst, int sym) retval = -1; goto exit; } +#if HAVE_CREATEHARDLINKW if (!sym && canHardLinkW(wsrc, wdst)) res = CreateHardLinkW(wdst, wsrc, NULL); else +#endif res = CopyFileW(wsrc, wdst, FALSE); } else { /* wsrc does not exist; try src prepend it with the dirname of wdst */ @@ -387,9 +391,11 @@ __link(const char *src, const char *dst, int sym) retval = -1; goto exit; } +#if HAVE_CREATEHARDLINKW if (!sym && canHardLinkW(wnewsrc, wdst)) res = CreateHardLinkW(wdst, wnewsrc, NULL); else +#endif res = CopyFileW(wnewsrc, wdst, FALSE); free (wnewsrc); }