Skip to content

Commit 1e1a876

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d166e6a commit 1e1a876

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

compat/mingw.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,24 +2211,12 @@ int mingw_raise(int sig)
22112211

22122212
int link(const char *oldpath, const char *newpath)
22132213
{
2214-
typedef BOOL (WINAPI *T)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
2215-
static T create_hard_link = NULL;
22162214
wchar_t woldpath[MAX_PATH], wnewpath[MAX_PATH];
22172215
if (xutftowcs_path(woldpath, oldpath) < 0 ||
22182216
xutftowcs_path(wnewpath, newpath) < 0)
22192217
return -1;
22202218

2221-
if (!create_hard_link) {
2222-
create_hard_link = (T) GetProcAddress(
2223-
GetModuleHandle("kernel32.dll"), "CreateHardLinkW");
2224-
if (!create_hard_link)
2225-
create_hard_link = (T)-1;
2226-
}
2227-
if (create_hard_link == (T)-1) {
2228-
errno = ENOSYS;
2229-
return -1;
2230-
}
2231-
if (!create_hard_link(wnewpath, woldpath, NULL)) {
2219+
if (!CreateHardLinkW(wnewpath, woldpath, NULL)) {
22322220
errno = err_win_to_posix(GetLastError());
22332221
return -1;
22342222
}

0 commit comments

Comments
 (0)