From 3c44f5cae158ff4ffd03a4c319777ae88a60bcb9 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 1 Mar 2021 09:31:21 +0000 Subject: Fix `xmalloc_readlink()` again In e86a3ddd8 (win32: make readlink(2) implementation unconditional, 2021-02-12), we removed the special casing of `errno == ENOSYS` when trying to follow symlinks. However, that handling really was necessary: - When we followed a symlink, and found a non-symlink, and then called `readlink()` with that non-symlink, we got `errno == ENOSYS` on Windows (translated from `ERROR_NOT_A_REPARSE_POINT`), and we did want to stop the loop and return the current path in that case. (Noted by Johannes Schindelin.) - When readlink() called DeviceIoControl() for files on certain filesystems (e.g. FAT or a CDROM) it returned `errno == ENOSYS` (translated from ERROR_INVALID_FUNCTION). Revert the part of the patch which handled `ENOSYS` on Windows. --- libbb/xreadlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index a18dd0748..ca53e12d3 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c @@ -64,7 +64,7 @@ char* FAST_FUNC xmalloc_follow_symlinks(const char *path) linkpath = xmalloc_readlink(buf); if (!linkpath) { /* not a symlink, or doesn't exist */ - if (errno == EINVAL || errno == ENOENT) + if (errno == EINVAL || errno == ENOENT || (ENABLE_PLATFORM_MINGW32 && errno == ENOSYS)) return buf; goto free_buf_ret_null; } -- cgit v1.2.3-55-g6feb