From 2765bddffa434dc4a6949dfcad8fce85c9564363 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 25 Mar 2018 18:34:56 +0200 Subject: [PATCH] [CRT] Various fixes to Wine file functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Import the following Wine commits: * ea2798f1ce9 Iván Matellanes: msvcrt: _setmode should check if file descriptor is valid. * 9b495caacfd Carlo Bramini: msvcrt: Call SetFilePointer() with correct parameters. * 13f34481b26 Carlo Bramini: msvcrt: Use MSVCRT_xxx macros instead of the same ones from GLIBC. * 781b069ed81 Piotr Caban: msvcrt: Don't close HANDLE if stdout or stderr is sharing it. --- sdk/lib/crt/stdio/file.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sdk/lib/crt/stdio/file.c b/sdk/lib/crt/stdio/file.c index b4c66856a3f..2357d99bfcb 100644 --- a/sdk/lib/crt/stdio/file.c +++ b/sdk/lib/crt/stdio/file.c @@ -936,6 +936,14 @@ int CDECL _close(int fd) TRACE(":fd (%d) handle (%p)\n", fd, info->handle); if (!(info->wxflag & WX_OPEN)) { ret = -1; + } else if (fd == STDOUT_FILENO && + info->handle == get_ioinfo_nolock(STDERR_FILENO)->handle) { + msvcrt_free_fd(fd); + ret = 0; + } else if (fd == STDERR_FILENO && + info->handle == get_ioinfo_nolock(STDOUT_FILENO)->handle) { + msvcrt_free_fd(fd); + ret = 0; } else { ret = CloseHandle(info->handle) ? 0 : -1; msvcrt_free_fd(fd); @@ -1237,7 +1245,7 @@ int CDECL _locking(int fd, int mode, LONG nbytes) (mode==_LK_NBRLCK)?"_LK_NBRLCK": "UNKNOWN"); - if ((cur_locn = SetFilePointer(info->handle, 0L, NULL, SEEK_CUR)) == INVALID_SET_FILE_POINTER) + if ((cur_locn = SetFilePointer(info->handle, 0L, NULL, FILE_CURRENT)) == INVALID_SET_FILE_POINTER) { release_ioinfo(info); FIXME ("Seek failed\n"); @@ -2480,6 +2488,11 @@ int CDECL _setmode(int fd,int mode) return -1; } + if(info == &__badioinfo) { + *_errno() = EBADF; + return EOF; + } + if(mode == _O_BINARY) { info->wxflag &= ~WX_TEXT; info->exflag &= ~(EF_UTF8|EF_UTF16);