From: Johannes Schindelin Date: Tue, 13 Nov 2018 14:37:02 +0000 (-0800) Subject: mingw: use `CreateHardLink()` directly X-Git-Tag: v2.20.0-rc0~8^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1e1a876bb2c895d59db8b7c8c4eb49ceef454bd3 mingw: use `CreateHardLink()` directly 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 Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff --git a/compat/mingw.c b/compat/mingw.c index d2f4fabb44..14ef81874d 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -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; }