Commit 307712613b77e8290a2c5d08ef3ae81c1e3139f3

Edward Thomson 2018-07-03T02:21:17

win32: use GetFinalPathNameByHandle directly Now that we've updated to WIN32_WINNT version of Vista or better, we don't need to dynamically load GetFinalPathNameByHandle and can simply invoke it directly.

diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 8617e45..1b7b939 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -35,9 +35,6 @@
  */
 #define WIN32_MODE_MASK (_S_IREAD | _S_IWRITE)
 
-/* GetFinalPathNameByHandleW signature */
-typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
-
 unsigned long git_win32__createfile_sharemode =
  FILE_SHARE_READ | FILE_SHARE_WRITE;
 int git_win32__retries = 10;
@@ -598,40 +595,13 @@ int p_getcwd(char *buffer_out, size_t size)
 	return 0;
 }
 
-/*
- * Returns the address of the GetFinalPathNameByHandleW function.
- * This function is available on Windows Vista and higher.
- */
-static PFGetFinalPathNameByHandleW get_fpnbyhandle(void)
-{
-	static PFGetFinalPathNameByHandleW pFunc = NULL;
-	PFGetFinalPathNameByHandleW toReturn = pFunc;
-
-	if (!toReturn) {
-		HMODULE hModule = GetModuleHandleW(L"kernel32");
-
-		if (hModule)
-			toReturn = (PFGetFinalPathNameByHandleW)GetProcAddress(hModule, "GetFinalPathNameByHandleW");
-
-		pFunc = toReturn;
-	}
-
-	assert(toReturn);
-
-	return toReturn;
-}
-
 static int getfinalpath_w(
 	git_win32_path dest,
 	const wchar_t *path)
 {
-	PFGetFinalPathNameByHandleW pgfp = get_fpnbyhandle();
 	HANDLE hFile;
 	DWORD dwChars;
 
-	if (!pgfp)
-		return -1;
-
 	/* Use FILE_FLAG_BACKUP_SEMANTICS so we can open a directory. Do not
 	* specify FILE_FLAG_OPEN_REPARSE_POINT; we want to open a handle to the
 	* target of the link. */
@@ -642,7 +612,7 @@ static int getfinalpath_w(
 		return -1;
 
 	/* Call GetFinalPathNameByHandle */
-	dwChars = pgfp(hFile, dest, GIT_WIN_PATH_UTF16, FILE_NAME_NORMALIZED);
+	dwChars = GetFinalPathNameByHandleW(hFile, dest, GIT_WIN_PATH_UTF16, FILE_NAME_NORMALIZED);
 	CloseHandle(hFile);
 
 	if (!dwChars || dwChars >= GIT_WIN_PATH_UTF16)