From 4e6d0dc9476e5cf43ff0bc5e66a54d812ddb4225 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 22 Feb 2018 11:40:53 +0000 Subject: win32: handle /dev/zero and /dev/urandom in open and read functions Currently /dev/zero is handled as a special case in dd. Add hacks to the open and read functions in mingw.c to handle the zero and urandom devices. - Opening /dev/zero or /dev/urandom actually opens the special Windows file 'nul' which behaves like /dev/null. This allows manipulation of the file descriptor with things like seek and close - When /dev/zero or /dev/urandom is opened the resulting file descriptor is stored and used to override the behaviour of read. - No attempt is made to track duplicated file descriptors, so using these devices for redirections in the shell isn't going to work and won't be permitted. (Could be, but won't.) - Limited control of the special file descriptors is provided by allowing the internal variables to be changed. - The numbers from /dev/urandom aren't very random. --- include/mingw.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/mingw.h') diff --git a/include/mingw.h b/include/mingw.h index a59ce6fc4..46be4dc23 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -395,6 +395,10 @@ int kill(pid_t pid, int sig); int link(const char *oldpath, const char *newpath); NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); int mingw_open (const char *filename, int oflags, ...); +void mingw_read_zero(int fd); +void mingw_read_random(int fd); +ssize_t mingw_read(int fd, void *buf, size_t count); +int mingw_close(int fd); int pipe(int filedes[2]); NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); NOIMPL(setgid,gid_t gid UNUSED_PARAM); @@ -418,6 +422,7 @@ int mingw_isatty(int fd); #define getcwd mingw_getcwd #define lchown chown #define open mingw_open +#define close mingw_close #define unlink mingw_unlink #define rmdir mingw_rmdir #undef lseek -- cgit v1.2.3-55-g6feb