From 36065f083a7eba3e0c6a9047c835b7efd1c61e9d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 23 Mar 2018 16:42:54 +0000 Subject: win32: save a few bytes in device file support --- win32/mingw.c | 70 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index d73a4d96e..8141e45a5 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -141,14 +141,33 @@ int err_win_to_posix(DWORD winerr) static int zero_fd = -1; static int rand_fd = -1; -void mingw_read_zero(int fd) +/* + * Determine if 'filename' corresponds to one of the supported + * device files. Constants for these are defined as an enum + * in mingw.h. + */ +int get_dev_type(const char *filename) { - zero_fd = fd; + int i; + const char *devname[NOT_DEVICE] = { "null", "zero", "urandom" }; + + if (filename && !strncmp(filename, "/dev/", 5)) { + for (i=0; i= 0) { + update_dev_fd(dev, fd); } - if (filename && !strncmp(filename, "/dev/", 5)) { - if (!strcmp(filename+5, "null")) { - devnull = 1; - } - else if (special) { - if (!strcmp(filename+5, "zero")) - devzero = 1; - else if (!strcmp(filename+5, "urandom")) - devrand = 1; - } - - if (devnull || devzero || devrand ) { - filename = "nul"; - oflags = O_RDWR; - } - } - fd = open(filename, oflags, mode); - if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) { + else if ((oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) { DWORD attrs = GetFileAttributes(filename); if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) errno = EISDIR; } - if (fd >= 0 ) { - if (devzero) - zero_fd = fd; - else if (devrand) - rand_fd = fd; - } return fd; } -- cgit v1.2.3-55-g6feb