http://bugs.winehq.org/show_bug.cgi?id=21291
Summary: System call "dup2" doesn't retain text vs binary mode Product: Wine Version: 1.0.1 Platform: x86 OS/Version: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: msvcrt AssignedTo: wine-bugs@winehq.org ReportedBy: simon@josefsson.org
Hi again, here is another "dup2" problem.
The attached code example behaves different in Wine compared to Windows XP. Under Wine it will print:
is_mode 1 dup2 3 => 0 is_mode 0
Note the last 'is_mode 0' which is the actual error. On Windows XP it prints:
is_mode 1 dup2 3 => 0 is_mode 1
The bug in the Wine "dup2" implementation appears to be that it doesn't copy the text/binary setting to the new file descriptor. Fixing it may be rather simple.
/Simon
jas@mocca:~$ cat foo2.c #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <stdio.h>
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include <windows.h> #endif
/* Return non-zero if FD is open in the given MODE, which is either O_TEXT or O_BINARY. */ static int is_mode (int fd, int mode) { int value = setmode (fd, O_BINARY); setmode (fd, value); return mode == value; }
int main (void) { const char *file = "test-dup2.tmp"; int fd = open (file, O_CREAT | O_TRUNC | O_RDWR, 0600);
setmode (fd, O_TEXT); printf ("is_mode %d\n", is_mode (fd, O_TEXT)); printf ("dup2 %d => %d\n", fd, dup2 (fd, fd + 1)); printf ("is_mode %d\n", is_mode (fd + 1, O_TEXT));
return 0; } jas@mocca:~$ i586-mingw32msvc-gcc -o foo2.exe foo2.c jas@mocca:~$ wine --version wine-1.0.1 jas@mocca:~$ wine ./foo2.exe is_mode 1 dup2 3 => 0 is_mode 0 jas@mocca:~$