aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/mingw.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 11ae09043..3183cd78e 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -185,6 +185,19 @@ void update_special_fd(int dev, int fd)
185 rand_fd = fd; 185 rand_fd = fd;
186} 186}
187 187
188#define PREFIX_LEN (sizeof(DEV_FD_PREFIX)-1)
189static int get_dev_fd(const char *filename)
190{
191 int fd;
192
193 if (filename && is_prefixed_with(filename, DEV_FD_PREFIX)) {
194 fd = bb_strtou(filename+PREFIX_LEN, NULL, 10);
195 if (errno == 0 && (HANDLE)_get_osfhandle(fd) != INVALID_HANDLE_VALUE)
196 return fd;
197 }
198 return -1;
199}
200
188#undef open 201#undef open
189int mingw_open (const char *filename, int oflags, ...) 202int mingw_open (const char *filename, int oflags, ...)
190{ 203{
@@ -199,6 +212,9 @@ int mingw_open (const char *filename, int oflags, ...)
199 filename = "nul"; 212 filename = "nul";
200 oflags = O_RDWR; 213 oflags = O_RDWR;
201 } 214 }
215 else if ((fd=get_dev_fd(filename)) >= 0) {
216 return fd;
217 }
202 218
203 va_start(args, oflags); 219 va_start(args, oflags);
204 mode = va_arg(args, int); 220 mode = va_arg(args, int);
@@ -240,8 +256,12 @@ ssize_t FAST_FUNC mingw_open_read_close(const char *fn, void *buf, size_t size)
240#undef fopen 256#undef fopen
241FILE *mingw_fopen (const char *filename, const char *otype) 257FILE *mingw_fopen (const char *filename, const char *otype)
242{ 258{
259 int fd;
260
243 if (get_dev_type(filename) == DEV_NULL) 261 if (get_dev_type(filename) == DEV_NULL)
244 filename = "nul"; 262 filename = "nul";
263 else if ((fd=get_dev_fd(filename)) >= 0)
264 return fdopen(fd, otype);
245 return fopen(filename, otype); 265 return fopen(filename, otype);
246} 266}
247 267