aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-02-16 09:48:48 +0000
committerRon Yorston <rmy@pobox.com>2020-02-16 09:48:48 +0000
commit8d443464257edcd04c8fa8d5a6f130b70535e115 (patch)
tree3fef845c2c39a43ce13ff973755507ad3bd4d463 /win32/mingw.c
parent800dbf203d5af67b9a115a4b6f1f84ca448bc755 (diff)
downloadbusybox-w32-8d443464257edcd04c8fa8d5a6f130b70535e115.tar.gz
busybox-w32-8d443464257edcd04c8fa8d5a6f130b70535e115.tar.bz2
busybox-w32-8d443464257edcd04c8fa8d5a6f130b70535e115.zip
win32: tidy up detection of device files
Define NOT_DEVICE as -1 so the return value of index_in_strings() when no device name is matched is NOT_DEVICE. Make the logic in mingw_open() clearer.
Diffstat (limited to 'win32/mingw.c')
-rw-r--r--win32/mingw.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 0863dc841..d6cd25107 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -156,14 +156,8 @@ static int rand_fd = -1;
156 */ 156 */
157int get_dev_type(const char *filename) 157int get_dev_type(const char *filename)
158{ 158{
159 int i; 159 if (filename && !strncmp(filename, "/dev/", 5))
160 160 return index_in_strings("null\0zero\0urandom\0", filename+5);
161 if (filename && !strncmp(filename, "/dev/", 5)) {
162 i = index_in_strings("null\0zero\0urandom\0", filename+5);
163 if (i != -1) {
164 return i;
165 }
166 }
167 161
168 return NOT_DEVICE; 162 return NOT_DEVICE;
169} 163}
@@ -186,7 +180,7 @@ int mingw_open (const char *filename, int oflags, ...)
186 int dev = get_dev_type(filename); 180 int dev = get_dev_type(filename);
187 181
188 /* /dev/null is always allowed, others only if O_SPECIAL is set */ 182 /* /dev/null is always allowed, others only if O_SPECIAL is set */
189 if (dev != NOT_DEVICE && (dev == DEV_NULL || special)) { 183 if (dev == DEV_NULL || (special && dev != NOT_DEVICE)) {
190 filename = "nul"; 184 filename = "nul";
191 oflags = O_RDWR; 185 oflags = O_RDWR;
192 } 186 }