Eric Blake <e...@byu.net> writes: > That said, here's a review of your proposed patch:
Thanks! Here is an updated patch that I will use in my projects. /Simon diff --git a/gltests/dup2.c b/gltests/dup2.c index a4422bf..b9b329c 100644 --- a/gltests/dup2.c +++ b/gltests/dup2.c @@ -40,6 +40,7 @@ rpl_dup2 (int fd, int desired_fd) { int result; # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + int fd_mode = -1; /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open, dup2 (fd, fd) returns 0, but all further attempts to use fd in future dup2 calls will hang. */ @@ -59,6 +60,14 @@ rpl_dup2 (int fd, int desired_fd) errno = EBADF; return -1; } + /* Wine 1.0.1 puts desired_fd into binary mode when fd is in text + mode, so we save the old mode here. + http://bugs.winehq.org/show_bug.cgi?id=21291 */ + if ((HANDLE) _get_osfhandle (fd) != (HANDLE) -1) + { + fd_mode = setmode (fd, O_BINARY); + setmode (fd, fd_mode); + } # endif result = dup2 (fd, desired_fd); # ifdef __linux__ @@ -80,6 +89,12 @@ rpl_dup2 (int fd, int desired_fd) if (fd != desired_fd && result != -1) result = _gl_register_dup (fd, result); # endif +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* Restore text mode if needed. + http://bugs.winehq.org/show_bug.cgi?id=21291 */ + if (result != -1 && fd_mode != -1) + setmode (desired_fd, fd_mode); +# endif return result; }