[Bug 21291] New: System call "dup2" doesn't retain text vs binary mode
wine-bugs at winehq.org
wine-bugs at winehq.org
Sat Jan 9 04:29:56 CST 2010
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 at winehq.org
ReportedBy: simon at 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 at 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 at mocca:~$ i586-mingw32msvc-gcc -o foo2.exe foo2.c
jas at mocca:~$ wine --version
wine-1.0.1
jas at mocca:~$ wine ./foo2.exe
is_mode 1
dup2 3 => 0
is_mode 0
jas at mocca:~$
--
Configure bugmail: http://bugs.winehq.org/userprefs.cgi?tab=email
Do not reply to this email, post in Bugzilla using the
above URL to reply.
------- You are receiving this mail because: -------
You are watching all bug changes.
More information about the wine-bugs
mailing list