From: Tim Kientzle Date: Mon, 31 Aug 2009 02:30:18 +0000 (-0400) Subject: Copy symlink/hardlink support routines from cpio/test X-Git-Tag: v2.8.0~404 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6ce156e13c1d4033f1ed66110468bc5b1391c41;p=thirdparty%2Flibarchive.git Copy symlink/hardlink support routines from cpio/test SVN-Revision: 1403 --- diff --git a/tar/test/main.c b/tar/test/main.c index dfa35a8b1..10bd5ec64 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -39,7 +39,6 @@ #endif #include #include -#include #ifndef F_OK #define F_OK (0) #endif @@ -64,6 +63,47 @@ #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); +} + +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 + /* * This same file is used pretty much verbatim for all test harnesses. * @@ -975,8 +1015,8 @@ test_assert_make_hardlink(const char *file, int line, int succeeded; count_assertion(file, line); -#if HAVE_CREATEHARDLINK - succeeded = CreateHardLink(newpath, linkto, NULL); +#if defined(_WIN32) && !defined(__CYGWIN__) + succeeded = __CreateHardLinkA(newpath, linkto); #elif HAVE_LINK succeeded = !link(linkto, newpath); #else @@ -997,10 +1037,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);