From afbf21c45d2e6a710aa27cb2784a540bb3ceedea Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 22 Jan 2023 09:42:18 +0000 Subject: win32: limit setting of errno when lazy loading fails The function get_proc_addr() facilitates dynamic loading of functions from DLLs. In the event of failure it set errno to ENOSYS. This is sometimes useful, such as in the implementations of link(2), symlink(2) and realpath(3). However, many other uses of lazy loading can recover from failure or simply don't care. In these cases setting errno is unnecessary and may be counterproductive. (GitHub issue #283) --- win32/mingw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 04908ba56..79bcaa47d 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1261,6 +1261,7 @@ int link(const char *oldpath, const char *newpath) LPSECURITY_ATTRIBUTES); if (!INIT_PROC_ADDR(kernel32.dll, CreateHardLinkA)) { + errno = ENOSYS; return -1; } if (!CreateHardLinkA(newpath, oldpath, NULL)) { @@ -1284,6 +1285,7 @@ int symlink(const char *target, const char *linkpath) char *targ, *relative = NULL; if (!INIT_PROC_ADDR(kernel32.dll, CreateSymbolicLinkA)) { + errno = ENOSYS; return -1; } @@ -1491,6 +1493,7 @@ static char *resolve_symlinks(char *path) FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h != INVALID_HANDLE_VALUE) { if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) { + errno = ENOSYS; goto end; } @@ -2279,9 +2282,6 @@ void *get_proc_addr(const char *dll, const char *function, proc->pfunction = GetProcAddress(hnd, function); proc->initialized = 1; } - /* set ENOSYS if DLL or function was not found */ - if (!proc->pfunction) - errno = ENOSYS; return proc->pfunction; } -- cgit v1.2.3-55-g6feb