aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2025-09-19 13:53:35 +0100
committerRon Yorston <rmy@pobox.com>2025-09-19 13:53:35 +0100
commit352bc560459d6dd24b3e6cb72f46ee8e37ba2efd (patch)
treedd114a086f2a106cb5fce88d3d0ac4d7b161509c
parent9b5938e9c5d1c09df03e67e2f0961e498fb36ba2 (diff)
downloadbusybox-w32-352bc560459d6dd24b3e6cb72f46ee8e37ba2efd.tar.gz
busybox-w32-352bc560459d6dd24b3e6cb72f46ee8e37ba2efd.tar.bz2
busybox-w32-352bc560459d6dd24b3e6cb72f46ee8e37ba2efd.zip
win32: use correct errno for fopen() of directory
We already fixed up errno when a directory was opened by open(). Do the same for fopen(). This allows grep to give a more useful error message when it's asked to open a directory. Adds 64 bytes. (GitHub issue #521)
-rw-r--r--win32/mingw.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 061e7bac6..529381b43 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -284,12 +284,17 @@ ssize_t FAST_FUNC mingw_open_read_close(const char *fn, void *buf, size_t size)
284FILE *mingw_fopen (const char *filename, const char *otype) 284FILE *mingw_fopen (const char *filename, const char *otype)
285{ 285{
286 int fd; 286 int fd;
287 FILE *stream;
287 288
288 if (get_dev_type(filename) == DEV_NULL) 289 if (get_dev_type(filename) == DEV_NULL)
289 filename = "nul"; 290 filename = "nul";
290 else if ((fd=get_dev_fd(filename)) >= 0) 291 else if ((fd=get_dev_fd(filename)) >= 0)
291 return fdopen(fd, otype); 292 return fdopen(fd, otype);
292 return fopen(filename, otype); 293 stream = fopen(filename, otype);
294 if (stream == NULL && errno == EACCES && strcmp(otype, "r") == 0 &&
295 mingw_is_directory(filename))
296 errno = EISDIR;
297 return stream;
293} 298}
294 299
295#undef read 300#undef read