From 8d443464257edcd04c8fa8d5a6f130b70535e115 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 16 Feb 2020 09:48:48 +0000 Subject: 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. --- win32/mingw.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'win32') 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; */ int get_dev_type(const char *filename) { - int i; - - if (filename && !strncmp(filename, "/dev/", 5)) { - i = index_in_strings("null\0zero\0urandom\0", filename+5); - if (i != -1) { - return i; - } - } + if (filename && !strncmp(filename, "/dev/", 5)) + return index_in_strings("null\0zero\0urandom\0", filename+5); return NOT_DEVICE; } @@ -186,7 +180,7 @@ int mingw_open (const char *filename, int oflags, ...) int dev = get_dev_type(filename); /* /dev/null is always allowed, others only if O_SPECIAL is set */ - if (dev != NOT_DEVICE && (dev == DEV_NULL || special)) { + if (dev == DEV_NULL || (special && dev != NOT_DEVICE)) { filename = "nul"; oflags = O_RDWR; } -- cgit v1.2.3-55-g6feb