mingw: use `CreateHardLink()` directly
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 13 Nov 2018 14:37:02 +0000 (06:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Nov 2018 05:41:15 +0000 (14:41 +0900)
The function `CreateHardLink()` is available in all supported Windows
versions (even since Windows XP), so there is no more need to resolve it
at runtime.

Helped-by: Max Kirillov <max@max630.net>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c
index d2f4fabb44b898ea6049b8b3fecadc26ddbb6253..14ef81874d182b12a3cb6581639398c63ab5eee3 100644 (file)
@@ -2211,24 +2211,12 @@ int mingw_raise(int sig)
 
 int link(const char *oldpath, const char *newpath)
 {
-       typedef BOOL (WINAPI *T)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
-       static T create_hard_link = NULL;
        wchar_t woldpath[MAX_PATH], wnewpath[MAX_PATH];
        if (xutftowcs_path(woldpath, oldpath) < 0 ||
                xutftowcs_path(wnewpath, newpath) < 0)
                return -1;
 
-       if (!create_hard_link) {
-               create_hard_link = (T) GetProcAddress(
-                       GetModuleHandle("kernel32.dll"), "CreateHardLinkW");
-               if (!create_hard_link)
-                       create_hard_link = (T)-1;
-       }
-       if (create_hard_link == (T)-1) {
-               errno = ENOSYS;
-               return -1;
-       }
-       if (!create_hard_link(wnewpath, woldpath, NULL)) {
+       if (!CreateHardLinkW(wnewpath, woldpath, NULL)) {
                errno = err_win_to_posix(GetLastError());
                return -1;
        }