When open() used O_RDONLY,dpopen(fd,rb) set bin-mode failed.
From: Deqiang Chen chendeqiang1024@qq.com
When open() used O_RDONLY,dpopen(fd,rb) set bin-mode failed. --- dlls/msvcrt/file.c | 5 ++++- dlls/msvcrt/tests/file.c | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index e72784eef41..b4b6c6c9602 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -632,7 +632,8 @@ static int msvcrt_init_fp(FILE* file, int fd, unsigned stream_flags) file->_file = fd; file->_flag = stream_flags; file->_tmpfname = NULL; - + if(stream_flags & _O_BINARY) _setmode(fd,_O_BINARY); + TRACE(":got FILE* (%p)\n",file); return 0; } @@ -1706,6 +1707,8 @@ static int msvcrt_get_flags(const wchar_t* mode, int *open_flags, int* stream_fl case 'B': case 'b': *open_flags |= _O_BINARY; *open_flags &= ~_O_TEXT; + *stream_flags |= _O_BINARY; + *stream_flags &= ~_O_TEXT; break; case 't': *open_flags |= _O_TEXT; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 3f57b3f871f..7e5d727df49 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -130,6 +130,7 @@ static void test_fdopen( void ) char ibuf[10]; int fd; FILE *file; + ioinfo *info;
fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE); write (fd, buffer, sizeof (buffer)); @@ -141,6 +142,12 @@ static void test_fdopen( void ) ok (fread (ibuf, 1, sizeof (buffer), file) == 5, "read wrong byte count\n"); ok (memcmp (ibuf, buffer + 5, 5) == 0, "read wrong bytes\n"); fclose (file); + + fd = open ("fdopen.tst", O_RDONLY); + file = fdopen (fd, "rb"); + info = &__pioinfo[fd/MSVCRT_FD_BLOCK_SIZE][fd%MSVCRT_FD_BLOCK_SIZE]; + ok((info->wxflag & WX_TEXT) == 0, "Couldn't set file bin mode, wxflag=%x, fd=%d \n",info->wxflag,fd); + fclose (file); unlink ("fdopen.tst"); }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=132760
Your paranoid android.
=== w7u_2qxl (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w7u_adm (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w7u_el (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w8 (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w8adm (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w864 (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064v1507 (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064v1809 (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064_tsign (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w10pro64 (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w11pro64 (32 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w7pro64 (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w864 (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064v1507 (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064v1809 (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064_2qxl (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064_adm (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w1064_tsign (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w10pro64 (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w10pro64_en_AE_u8 (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w10pro64_ar (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w10pro64_ja (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w10pro64_zh_CN (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== w11pro64_amd (64 bit report) ===
msvcrt: file.c:149: Test failed: Couldn't set file bin mode, wxflag=81, fd=3
=== debian11 (32 bit report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit ar:MA report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit de report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit fr report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit he:IL report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit hi:IN report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit ja:JP report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11 (32 bit zh:CN report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11b (32 bit WoW report) ===
msvcrt: file.c:410: Test failed: fread succeeded
=== debian11b (64 bit WoW report) ===
msvcrt: file.c:410: Test failed: fread succeeded
I have tested that fdopen() can't be used to change fd mode (I've checked msvcr120 and ucrtbase, msvcrt was checked by your tests). That means that current behavior is correct.
I'm closing this MR. Please open new one if you find different solution for the problem you're trying to fix.
This merge request was closed by Piotr Caban.
On Thu May 18 06:17:52 2023 +0000, Piotr Caban wrote:
I have tested that fdopen() can't be used to change fd mode (I've checked msvcr120 and ucrtbase, msvcrt was checked by your tests). That means that current behavior is correct. I'm closing this MR. Please open new one if you find different solution for the problem you're trying to fix.
The patch resolved a Pipelight bug, but I do not know why Windows can`t be passed. Can you tell me why Windows and Linux are not same ? Thanks!
On Thu May 18 06:18:47 2023 +0000, Deqiang Chen wrote:
The patch resolved a Pipelight bug, but I do not know why Windows can`t be passed. Can you tell me why Windows and Linux are not same ? Thanks!
I'm not sure what you mean, there's no equivalent of _O_BINARY flag in GLIBC. I guess that "b" in fdmode mode parameter is ignored on Linux.
You will probably need to debug Pipelight to find where the bug is. You can start by running it with native msvcr*.dll to see if the bug is in this component.