]> git.proxmox.com Git - libgit2.git/commitdiff
fileops: Fix 'GetFinalPathNameByHandleA' in old platforms
authorVicent Marti <tanoku@gmail.com>
Fri, 17 Jun 2011 17:08:06 +0000 (19:08 +0200)
committerVicent Marti <tanoku@gmail.com>
Fri, 17 Jun 2011 17:09:18 +0000 (19:09 +0200)
src/fileops.c

index 58bc65c454b6696b3a147ad7f6c7d1d212cc6991..12b28bf02165355b272f756ebc5f3a86cadc2ae1 100644 (file)
@@ -689,9 +689,25 @@ int gitfo_lstat__w32(const char *file_name, struct stat *buf)
 
 int gitfo_readlink__w32(const char *link, char *target, size_t target_len)
 {
+       static DWORD (*pGetFinalPath)(HANDLE, LPTSTR, DWORD, DWORD) = NULL;
        HANDLE hFile;
        DWORD dwRet;
 
+       /*
+        * Try to load the pointer to pGetFinalPath dynamically, because
+        * it is not available in platforms older than Vista
+        */
+       if (pGetFinalPath == NULL) {
+               HANDLE library = LoadLibrary("kernel32");
+
+               if (library != NULL)
+                       pGetFinalPath = GetProcAddress(library, "GetFinalPathNameByHandleA");
+
+               if (pGetFinalPath == NULL)
+                       return git__throw(GIT_EOSERR,
+                               "'GetFinalPathNameByHandleA' is not available in this platform");
+       }
+
        hFile = CreateFile(link,            // file to open
                                 GENERIC_READ,          // open for reading
                                 FILE_SHARE_READ,       // share for reading
@@ -703,7 +719,7 @@ int gitfo_readlink__w32(const char *link, char *target, size_t target_len)
        if (hFile == INVALID_HANDLE_VALUE)
                return GIT_EOSERR;
 
-       dwRet = GetFinalPathNameByHandleA(hFile, target, target_len, VOLUME_NAME_DOS);
+       dwRet = pGetFinalPath(hFile, target, target_len, VOLUME_NAME_DOS);
        if (dwRet >= target_len)
                return GIT_ENOMEM;