[CRT] Various fixes to Wine file functions.

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.
This commit is contained in:
Thomas Faber 2018-03-25 18:34:56 +02:00
parent 6aa8e3cc20
commit 2765bddffa
No known key found for this signature in database
GPG key ID: 076E7C3D44720826

View file

@ -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);