From 446a0f5d2f78962fe661e3c2a292660786b5decd Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 14 Jun 2017 08:20:42 -0700 Subject: [PATCH] WIN32: Make dup2 a NO-OP under win32. There is something wrong with dup2 under win32 and I do not know win32 well enough to fix it, thus this workaround. Signed-off-by: Ronnie Sahlberg --- win32/win32_compat.c | 16 ++++++++++++++++ win32/win32_compat.h | 1 + 2 files changed, 17 insertions(+) diff --git a/win32/win32_compat.c b/win32/win32_compat.c index cda19a4..8c797be 100644 --- a/win32/win32_compat.c +++ b/win32/win32_compat.c @@ -208,4 +208,20 @@ ssize_t win32_writev(int fd, const struct iovec *iov, int iovcnt) return send(fd, iov[0].iov_base, iov[0].iov_len, 0); } +/* Something is broken with how I use dup2 for windows and I do not know + * win32 API well enought to figure out why, thus our dup2 for win32 will be + * a NO-OP. + * The only consequence of this is that the filedescriptor for libiscsi may + * now suddenly change under win32. As long as the application just calls + * iscsi_get_fd() before poll or its equivalent every time ot goes through + * its event loop, everything should work. + * IF the app tries to be clever/optimized and only calls iscsi_get_fd() + * one single time and re-uses that file descriptor number throughout + * any future iterations in the event loop, then things will break :-( + */ +int win32_dup2(int oldfd, int newfd) +{ + return 0; +} + #endif diff --git a/win32/win32_compat.h b/win32/win32_compat.h index 9d07a72..62330f6 100644 --- a/win32/win32_compat.h +++ b/win32/win32_compat.h @@ -65,6 +65,7 @@ typedef int socklen_t; #define writev win32_writev #define strncasecmp _strnicmp #define strdup _strdup +#define dup2(x, y, z) win32_dup2(x, y) #define poll(x, y, z) win32_poll(x, y, z) #define inet_pton(x,y,z) win32_inet_pton(x,y,z) #define sleep(x) Sleep(x * 1000)