Message ID | pull.1402.v2.git.git.1671466826159.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] win32: explicitly set errno to enoent if err is not error_directory | expand |
Am 19.12.22 um 17:20 schrieb Rose via GitGitGadget: > From: Seija Kijin <doremylover123@gmail.com> > > At this point, the only two possible errors are > ERROR_DIRECTORY or ERROR_BAD_PATHNAME. > > This code clarifies this and also saves a call to > err_win_to_posix. > > Signed-off-by: Seija Kijin <doremylover123@gmail.com> > --- > diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c > index 52420ec7d4d..8f94a5ab6db 100644 > --- a/compat/win32/dirent.c > +++ b/compat/win32/dirent.c > @@ -34,13 +34,13 @@ DIR *opendir(const char *name) > if (len && !is_dir_sep(pattern[len - 1])) > pattern[len++] = '/'; > pattern[len++] = '*'; > - pattern[len] = 0; > + pattern[len] = '\0'; > > /* open find handle */ > h = FindFirstFileW(pattern, &fdata); > if (h == INVALID_HANDLE_VALUE) { > DWORD err = GetLastError(); > - errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err); > + errno = (err == ERROR_DIRECTORY) ? ENOTDIR : ENOENT; This change does not look correct. The documentation of FindFirstFileW()[*] does not give any guarantees that ERROR_DIRECTORY and ERROR_BAD_PATHNAME are the only possible error values. It is certainly not unthinkable that a hardware error is reported as ERROR_IO_DEVICE and should be translated to EIO. [*] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilew -- Hannes
diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c index 52420ec7d4d..8f94a5ab6db 100644 --- a/compat/win32/dirent.c +++ b/compat/win32/dirent.c @@ -34,13 +34,13 @@ DIR *opendir(const char *name) if (len && !is_dir_sep(pattern[len - 1])) pattern[len++] = '/'; pattern[len++] = '*'; - pattern[len] = 0; + pattern[len] = '\0'; /* open find handle */ h = FindFirstFileW(pattern, &fdata); if (h == INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); - errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err); + errno = (err == ERROR_DIRECTORY) ? ENOTDIR : ENOENT; return NULL; }