From: Tim Kientzle Date: Tue, 1 Sep 2009 01:34:07 +0000 (-0400) Subject: CreateHardLinkA is supported on Win2k and later, which is good X-Git-Tag: v2.8.0~396 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61bd67921f78154fc5614202e2717b819c51d379;p=thirdparty%2Flibarchive.git CreateHardLinkA is supported on Win2k and later, which is good enough for now. (Plus, I was having inexplicable problems getting the dynamic probe to work for this function.) SVN-Revision: 1411 --- diff --git a/configure.ac b/configure.ac index 53bfab0e0..60ae3d2a0 100644 --- a/configure.ac +++ b/configure.ac @@ -335,7 +335,7 @@ AC_FUNC_STAT AC_FUNC_STRERROR_R AC_FUNC_STRFTIME AC_FUNC_VPRINTF -AC_CHECK_FUNCS([CreateHardLink CreateSymbolicLink]) +AC_CHECK_FUNCS([CreateHardLinkA CreateSymbolicLink]) AC_CHECK_FUNCS([chflags chown chroot]) AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fcntl fork]) AC_CHECK_FUNCS([fstat ftruncate futimes geteuid getpid]) diff --git a/cpio/test/main.c b/cpio/test/main.c index a45485c9c..e8efa4c85 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -90,18 +90,6 @@ int __CreateSymbolicLinkA(const char *linkname, const char *target, int flags) return f == NULL ? 0 : (*f)(linkname, target, flags); } -int __CreateHardLinkA(const char *linkname, const char *target) -{ - static BOOLEAN (*f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateHardLinkA"); - } - if (f == NULL) - return 0; - return (*f)(linkname, target, NULL); -} #endif /* @@ -1015,10 +1003,10 @@ test_assert_make_hardlink(const char *file, int line, int succeeded; count_assertion(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - succeeded = __CreateHardLinkA(newpath, linkto); -#elif HAVE_LINK +#if HAVE_LINK succeeded = !link(linkto, newpath); +#elif HAVE_CREATEHARDLINKA + succeeded = CreateHardLinkA(newpath, linkto, NULL); #else succeeded = 0; #endif diff --git a/libarchive/test/main.c b/libarchive/test/main.c index c3b48af4e..b49fb1a31 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -39,7 +39,6 @@ #endif #include #include -#include #ifndef F_OK #define F_OK (0) #endif @@ -64,6 +63,35 @@ #define umask _umask #endif +#if defined(_WIN32) && !defined(__CYGWIN__) +void *GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + return NULL; + } + return (void *)GetProcAddress(lib, name); +} + +int __CreateSymbolicLinkA(const char *linkname, const char *target, int flags) +{ + static BOOLEAN (*f)(LPCSTR, LPCSTR, DWORD); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateSymbolicLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, flags); +} + +#endif + /* * This same file is used pretty much verbatim for all test harnesses. * @@ -974,10 +1002,10 @@ test_assert_make_hardlink(const char *file, int line, int succeeded; count_assertion(file, line); -#if HAVE_CREATEHARDLINK - succeeded = CreateHardLink(newpath, linkto, NULL); -#elif HAVE_LINK +#if HAVE_LINK succeeded = !link(linkto, newpath); +#elif HAVE_CREATEHARDLINKA + succeeded = CreateHardLinkA(newpath, linkto, NULL); #else succeeded = 0; #endif @@ -996,10 +1024,10 @@ int test_assert_make_symlink(const char *file, int line, const char *newpath, const char *linkto) { -#if HAVE_CREATESYMBOLICLINK - int targetIsDir = 0; /* TODO: Fix this. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + int targetIsDir = 0; /* TODO: Fix this */ count_assertion(file, line); - if (CreateSymbolicLink(newpath, linkto, targetIsDir)) + if (__CreateSymbolicLinkA(newpath, linkto, targetIsDir)) return (1); #elif HAVE_SYMLINK count_assertion(file, line); diff --git a/tar/test/main.c b/tar/test/main.c index 452b6da61..0e148a1bd 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -90,21 +90,6 @@ int __CreateSymbolicLinkA(const char *linkname, const char *target, int flags) return f == NULL ? 0 : (*f)(linkname, target, flags); } -int __CreateHardLinkA(const char *linkname, const char *target) -{ - return CreateHardLinkA(linkname, target, NULL); -#if 0 - static BOOLEAN (*f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateHardLinkA"); - } - if (f == NULL) - return 0; - return (*f)(linkname, target, NULL); -#endif -} #endif /* @@ -1018,10 +1003,10 @@ test_assert_make_hardlink(const char *file, int line, int succeeded; count_assertion(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - succeeded = __CreateHardLinkA(newpath, linkto); -#elif HAVE_LINK +#if HAVE_LINK succeeded = !link(linkto, newpath); +#elif HAVE_CREATEHARDLINKA + succeeded = CreateHardLinkA(newpath, linkto, NULL); #else succeeded = 0; #endif