[CRT] stdio/file.c: Import 3 Wine one-liner fixes (#4101)

* [FORMATTING][CRT] stdio/file.c: Reduce diff with Wine.

* [CRT] _wfreopen(): Fix TRACE() format modifier
Import wine-1.4-rc3 f8b29a0 by Eric Pouech.

* [CRT] msvcrt_init_io(): Ignore inherited FDs with invalid handles
Import wine-6.2-32-g611742d by Paul Gofman,
except test part, which shall be WineSync separately.

* [CRT] _dup2(): Fix clearing NOINHERIT flag
Import wine-6.20-44-g1420d28 by Piotr Caban.
This commit is contained in:
Serge Gautherie 2021-11-18 23:23:12 +01:00 committed by GitHub
parent 83335d3a81
commit 0a6750da12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -474,7 +474,7 @@ void msvcrt_init_io(void)
count = min(count, MSVCRT_MAX_FILES); count = min(count, MSVCRT_MAX_FILES);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
if ((*wxflag_ptr & WX_OPEN) && *handle_ptr != INVALID_HANDLE_VALUE) if ((*wxflag_ptr & WX_OPEN) && GetFileType(*handle_ptr) != FILE_TYPE_UNKNOWN)
{ {
fdinfo = get_ioinfo_alloc_fd(i); fdinfo = get_ioinfo_alloc_fd(i);
if(fdinfo != &__badioinfo) if(fdinfo != &__badioinfo)
@ -831,16 +831,17 @@ int CDECL _commit(int fd)
int ret; int ret;
TRACE(":fd (%d) handle (%p)\n", fd, info->handle); TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
if (info->handle == INVALID_HANDLE_VALUE) if (info->handle == INVALID_HANDLE_VALUE)
ret = -1; ret = -1;
else if (!FlushFileBuffers(info->handle)) else if (!FlushFileBuffers(info->handle))
{ {
if (GetLastError() == ERROR_INVALID_HANDLE) if (GetLastError() == ERROR_INVALID_HANDLE)
{ {
/* FlushFileBuffers fails for console handles /* FlushFileBuffers fails for console handles
* so we ignore this error. * so we ignore this error.
*/ */
ret = 0; ret = 0;
} }
else else
{ {
@ -992,7 +993,7 @@ int CDECL _dup2(int od, int nd)
if (DuplicateHandle(GetCurrentProcess(), info_od->handle, if (DuplicateHandle(GetCurrentProcess(), info_od->handle,
GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS)) GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS))
{ {
int wxflag = info_od->wxflag & ~_O_NOINHERIT; int wxflag = info_od->wxflag & ~WX_DONTINHERIT;
if (info_nd->wxflag & WX_OPEN) if (info_nd->wxflag & WX_OPEN)
_close(nd); _close(nd);
@ -1669,7 +1670,7 @@ wchar_t * CDECL _wmktemp(wchar_t *pattern)
/*static*/ unsigned split_oflags(unsigned oflags) /*static*/ unsigned split_oflags(unsigned oflags)
{ {
int wxflags = 0; int wxflags = 0;
unsigned unsupp; /* until we support everything */ unsigned unsupp; /* until we support everything */
if (oflags & _O_APPEND) wxflags |= WX_APPEND; if (oflags & _O_APPEND) wxflags |= WX_APPEND;
@ -1871,7 +1872,7 @@ int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int
return *_errno(); return *_errno();
} }
if (oflags & (_O_WTEXT|_O_U16TEXT|_O_U8TEXT)) if (oflags & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT))
{ {
if ((access & GENERIC_WRITE) && (creation==CREATE_NEW if ((access & GENERIC_WRITE) && (creation==CREATE_NEW
|| creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING
@ -3419,7 +3420,7 @@ FILE* CDECL _wfreopen(const wchar_t *path, const wchar_t *mode, FILE* file)
{ {
int open_flags, stream_flags, fd; int open_flags, stream_flags, fd;
TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1); TRACE(":path (%s) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1);
LOCK_FILES(); LOCK_FILES();
if (!file || ((fd = file->_file) < 0)) if (!file || ((fd = file->_file) < 0))