aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-02-15 11:02:07 +0000
committerRon Yorston <rmy@pobox.com>2020-02-15 12:32:08 +0000
commitadb70e66cffcd47255fc61f109d617b48f7fddd2 (patch)
treeb2926561f1e84dafd9efe243ded0e58601a9ed04
parent99f757c114ffbbdc9bfcb665fe2091982122a3db (diff)
downloadbusybox-w32-adb70e66cffcd47255fc61f109d617b48f7fddd2.tar.gz
busybox-w32-adb70e66cffcd47255fc61f109d617b48f7fddd2.tar.bz2
busybox-w32-adb70e66cffcd47255fc61f109d617b48f7fddd2.zip
win32: rework device file detection
Improve get_dev_type() and use it to dectect /dev/null in mingw_xopen(). Saves 64 bytes.
-rw-r--r--win32/mingw.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index bada160da..0863dc841 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -157,13 +157,11 @@ static int rand_fd = -1;
157int get_dev_type(const char *filename) 157int get_dev_type(const char *filename)
158{ 158{
159 int i; 159 int i;
160 const char *devname[NOT_DEVICE] = { "null", "zero", "urandom" };
161 160
162 if (filename && !strncmp(filename, "/dev/", 5)) { 161 if (filename && !strncmp(filename, "/dev/", 5)) {
163 for (i=0; i<NOT_DEVICE; ++i ) { 162 i = index_in_strings("null\0zero\0urandom\0", filename+5);
164 if (!strcmp(filename+5, devname[i])) { 163 if (i != -1) {
165 return i; 164 return i;
166 }
167 } 165 }
168 } 166 }
169 167
@@ -224,7 +222,7 @@ int mingw_xopen(const char *pathname, int flags)
224#undef fopen 222#undef fopen
225FILE *mingw_fopen (const char *filename, const char *otype) 223FILE *mingw_fopen (const char *filename, const char *otype)
226{ 224{
227 if (filename && !strcmp(filename, "/dev/null")) 225 if (get_dev_type(filename) == DEV_NULL)
228 filename = "nul"; 226 filename = "nul";
229 return fopen(filename, otype); 227 return fopen(filename, otype);
230} 228}