diff options
author | Ron Yorston <rmy@pobox.com> | 2023-01-22 09:42:18 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-01-22 09:50:48 +0000 |
commit | afbf21c45d2e6a710aa27cb2784a540bb3ceedea (patch) | |
tree | 0a4e68be3233f251cd5b6cd8f54b6a7132d3a5ed | |
parent | 728738553fb473e4ad9f2c4efc88e7e28fcda20d (diff) | |
download | busybox-w32-afbf21c45d2e6a710aa27cb2784a540bb3ceedea.tar.gz busybox-w32-afbf21c45d2e6a710aa27cb2784a540bb3ceedea.tar.bz2 busybox-w32-afbf21c45d2e6a710aa27cb2784a540bb3ceedea.zip |
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)
-rw-r--r-- | win32/mingw.c | 6 |
1 files 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) | |||
1261 | LPSECURITY_ATTRIBUTES); | 1261 | LPSECURITY_ATTRIBUTES); |
1262 | 1262 | ||
1263 | if (!INIT_PROC_ADDR(kernel32.dll, CreateHardLinkA)) { | 1263 | if (!INIT_PROC_ADDR(kernel32.dll, CreateHardLinkA)) { |
1264 | errno = ENOSYS; | ||
1264 | return -1; | 1265 | return -1; |
1265 | } | 1266 | } |
1266 | if (!CreateHardLinkA(newpath, oldpath, NULL)) { | 1267 | if (!CreateHardLinkA(newpath, oldpath, NULL)) { |
@@ -1284,6 +1285,7 @@ int symlink(const char *target, const char *linkpath) | |||
1284 | char *targ, *relative = NULL; | 1285 | char *targ, *relative = NULL; |
1285 | 1286 | ||
1286 | if (!INIT_PROC_ADDR(kernel32.dll, CreateSymbolicLinkA)) { | 1287 | if (!INIT_PROC_ADDR(kernel32.dll, CreateSymbolicLinkA)) { |
1288 | errno = ENOSYS; | ||
1287 | return -1; | 1289 | return -1; |
1288 | } | 1290 | } |
1289 | 1291 | ||
@@ -1491,6 +1493,7 @@ static char *resolve_symlinks(char *path) | |||
1491 | FILE_FLAG_BACKUP_SEMANTICS, NULL); | 1493 | FILE_FLAG_BACKUP_SEMANTICS, NULL); |
1492 | if (h != INVALID_HANDLE_VALUE) { | 1494 | if (h != INVALID_HANDLE_VALUE) { |
1493 | if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) { | 1495 | if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) { |
1496 | errno = ENOSYS; | ||
1494 | goto end; | 1497 | goto end; |
1495 | } | 1498 | } |
1496 | 1499 | ||
@@ -2279,9 +2282,6 @@ void *get_proc_addr(const char *dll, const char *function, | |||
2279 | proc->pfunction = GetProcAddress(hnd, function); | 2282 | proc->pfunction = GetProcAddress(hnd, function); |
2280 | proc->initialized = 1; | 2283 | proc->initialized = 1; |
2281 | } | 2284 | } |
2282 | /* set ENOSYS if DLL or function was not found */ | ||
2283 | if (!proc->pfunction) | ||
2284 | errno = ENOSYS; | ||
2285 | return proc->pfunction; | 2285 | return proc->pfunction; |
2286 | } | 2286 | } |
2287 | 2287 | ||