From a36568cdf1f9bee317fdace64dfa5bc3aae0b3ad Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 10 Jan 2017 23:14:20 +0100 Subject: [PATCH] mingw: simplify loading the CreadHardLinkW() function We introduced helper macros to simplify loading functions dynamically. Might just as well use them. Signed-off-by: Karsten Blees Signed-off-by: Johannes Schindelin --- compat/mingw.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 32ae421d07..23270817d0 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2124,24 +2124,18 @@ 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; + DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateHardLinkW, + LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); wchar_t woldpath[MAX_LONG_PATH], wnewpath[MAX_LONG_PATH]; + + if (!INIT_PROC_ADDR(CreateHardLinkW)) + return -1; + if (xutftowcs_long_path(woldpath, oldpath) < 0 || xutftowcs_long_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; }