msvcrt: Fix errno set on dup from read-only file.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53950
This commit is contained in:
Michel Zou 2022-11-26 18:27:52 +01:00 committed by Alexandre Julliard
parent 7ca1eff8e1
commit 53bc6c7a4a
2 changed files with 7 additions and 0 deletions

View file

@ -1244,6 +1244,7 @@ int CDECL _dup2(int od, int nd)
if (info_nd == &MSVCRT___badioinfo)
{
*_errno() = EBADF;
ret = -1;
}
else if (info_od->wxflag & WX_OPEN)

View file

@ -267,6 +267,12 @@ static void test_readmode( BOOL ascii_mode )
close (fd);
fd = open ("fdopen.tst", O_RDONLY, _S_IREAD |_S_IWRITE);
errno = 0xdeadbeef;
ok(dup2(fd, -1) == -1, "dup2(fd, -1) succeeded\n");
ok(errno == EBADF, "errno = %d\n", errno);
close (fd);
if (ascii_mode) {
/* Open file in ascii mode */
fd = open ("fdopen.tst", O_RDONLY);