aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/dd.c4
-rw-r--r--coreutils/shred.c4
-rw-r--r--include/mingw.h2
-rw-r--r--win32/mingw.c31
4 files changed, 33 insertions, 8 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 4362ae798..10066575e 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -429,8 +429,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
429#endif 429#endif
430 430
431 if (infile) { 431 if (infile) {
432#if !ENABLE_PLATFORM_MINGW32
432 xmove_fd(xopen(infile, O_RDONLY), ifd); 433 xmove_fd(xopen(infile, O_RDONLY), ifd);
433#if ENABLE_PLATFORM_MINGW32 434#else
435 xmove_fd(mingw_xopen(infile, O_RDONLY), ifd);
434 if (!strcmp(infile, "/dev/zero")) { 436 if (!strcmp(infile, "/dev/zero")) {
435 mingw_read_zero(ifd); 437 mingw_read_zero(ifd);
436 } 438 }
diff --git a/coreutils/shred.c b/coreutils/shred.c
index 1b65a359e..0ebbc39ca 100644
--- a/coreutils/shred.c
+++ b/coreutils/shred.c
@@ -38,6 +38,10 @@
38 38
39#include "libbb.h" 39#include "libbb.h"
40 40
41#if ENABLE_PLATFORM_MINGW32
42#define xopen mingw_xopen
43#endif
44
41int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 45int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
42int shred_main(int argc UNUSED_PARAM, char **argv) 46int shred_main(int argc UNUSED_PARAM, char **argv)
43{ 47{
diff --git a/include/mingw.h b/include/mingw.h
index 09903d582..386540b37 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -30,6 +30,7 @@ int inet_pton(int af, const char *src, void *dst);
30#define FD_CLOEXEC 0x1 30#define FD_CLOEXEC 0x1
31#define O_NONBLOCK 0 31#define O_NONBLOCK 0
32#define O_NOFOLLOW 0 32#define O_NOFOLLOW 0
33#define O_SPECIAL 0x800000
33 34
34/* 35/*
35 * grp.h 36 * grp.h
@@ -367,6 +368,7 @@ int kill(pid_t pid, int sig);
367int link(const char *oldpath, const char *newpath); 368int link(const char *oldpath, const char *newpath);
368NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); 369NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM);
369int mingw_open (const char *filename, int oflags, ...); 370int mingw_open (const char *filename, int oflags, ...);
371int mingw_xopen(const char *filename, int oflags);
370void mingw_read_zero(int fd); 372void mingw_read_zero(int fd);
371void mingw_read_random(int fd); 373void mingw_read_random(int fd);
372ssize_t mingw_read(int fd, void *buf, size_t count); 374ssize_t mingw_read(int fd, void *buf, size_t count);
diff --git a/win32/mingw.c b/win32/mingw.c
index f9967f1c4..981c50415 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -157,6 +157,7 @@ int mingw_open (const char *filename, int oflags, ...)
157 va_list args; 157 va_list args;
158 unsigned mode; 158 unsigned mode;
159 int fd; 159 int fd;
160 int special = 0;
160 int devnull = 0; 161 int devnull = 0;
161 int devzero = 0; 162 int devzero = 0;
162 int devrand = 0; 163 int devrand = 0;
@@ -165,16 +166,20 @@ int mingw_open (const char *filename, int oflags, ...)
165 mode = va_arg(args, int); 166 mode = va_arg(args, int);
166 va_end(args); 167 va_end(args);
167 168
168 if (oflags & O_NONBLOCK) { 169 if (oflags & O_SPECIAL) {
169 oflags &= ~O_NONBLOCK; 170 oflags &= ~O_SPECIAL;
171 special = 1;
170 } 172 }
171 if (filename && !strncmp(filename, "/dev/", 5)) { 173 if (filename && !strncmp(filename, "/dev/", 5)) {
172 if (!strcmp(filename+5, "null")) 174 if (!strcmp(filename+5, "null")) {
173 devnull = 1; 175 devnull = 1;
174 else if (!strcmp(filename+5, "zero")) 176 }
175 devzero = 1; 177 else if (special) {
176 else if (!strcmp(filename+5, "urandom")) 178 if (!strcmp(filename+5, "zero"))
177 devrand = 1; 179 devzero = 1;
180 else if (!strcmp(filename+5, "urandom"))
181 devrand = 1;
182 }
178 183
179 if (devnull || devzero || devrand ) 184 if (devnull || devzero || devrand )
180 filename = "nul"; 185 filename = "nul";
@@ -194,6 +199,18 @@ int mingw_open (const char *filename, int oflags, ...)
194 return fd; 199 return fd;
195} 200}
196 201
202int mingw_xopen(const char *pathname, int flags)
203{
204 int ret;
205
206 /* allow use of special devices */
207 ret = mingw_open(pathname, flags|O_SPECIAL);
208 if (ret < 0) {
209 bb_perror_msg_and_die("can't open '%s'", pathname);
210 }
211 return ret;
212}
213
197#undef fopen 214#undef fopen
198FILE *mingw_fopen (const char *filename, const char *otype) 215FILE *mingw_fopen (const char *filename, const char *otype)
199{ 216{