diff options
author | Ron Yorston <rmy@pobox.com> | 2021-06-07 09:03:01 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-06-07 11:30:46 +0100 |
commit | 9ba9333e913c617e995b2e1d37dc738b77304158 (patch) | |
tree | 8d9dcdeb79060896ca214ed0607992f530a25090 | |
parent | cdd0e9946a45dd69dc0bc8a8d0bcb734c7234937 (diff) | |
download | busybox-w32-9ba9333e913c617e995b2e1d37dc738b77304158.tar.gz busybox-w32-9ba9333e913c617e995b2e1d37dc738b77304158.tar.bz2 busybox-w32-9ba9333e913c617e995b2e1d37dc738b77304158.zip |
win32: let virtual /dev/fd/<num> files be opened
Add support for virtual /dev/fd files to represent file descriptors.
-rw-r--r-- | include/platform.h | 2 | ||||
-rw-r--r-- | win32/mingw.c | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/include/platform.h b/include/platform.h index b2d918643..37e48dcc5 100644 --- a/include/platform.h +++ b/include/platform.h | |||
@@ -447,6 +447,8 @@ typedef unsigned smalluint; | |||
447 | #define HAVE_SYS_STATFS_H 1 | 447 | #define HAVE_SYS_STATFS_H 1 |
448 | #define HAVE_PRINTF_PERCENTM 1 | 448 | #define HAVE_PRINTF_PERCENTM 1 |
449 | #define HAVE_WAIT3 1 | 449 | #define HAVE_WAIT3 1 |
450 | #define HAVE_DEV_FD 1 | ||
451 | #define DEV_FD_PREFIX "/dev/fd/" | ||
450 | 452 | ||
451 | #if defined(__UCLIBC__) | 453 | #if defined(__UCLIBC__) |
452 | # if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32) | 454 | # if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32) |
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) | ||
189 | static 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 |
189 | int mingw_open (const char *filename, int oflags, ...) | 202 | int 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 |
241 | FILE *mingw_fopen (const char *filename, const char *otype) | 257 | FILE *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 | ||