This fixes a regression in running MSVC 2010 in wine, when reading .def files (regressed in b0ab1b76029eaface724a28483fe8b0ea36029dc).
Signed-off-by: Martin Storsjo martin@martin.st --- dlls/msvcrt/file.c | 1 + dlls/msvcrt/tests/file.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index ba534568119..258ae2ac811 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2184,6 +2184,7 @@ static int check_bom(HANDLE h, int oflags, BOOL seek) oflags = (oflags & ~(_O_WTEXT | _O_U8TEXT)) | _O_U16TEXT; }else if (seek) { SetFilePointer(h, 0, NULL, FILE_BEGIN); + oflags = oflags & ~_O_WTEXT; }
return oflags; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index ecf99e38b0e..b094ca5d1e8 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -1039,6 +1039,43 @@ static void test_fgetwc_unicode(void) ch = fgetwc(tempfh); ok(ch == WEOF, "got %04hx, expected WEOF (unicode)\n", ch); fclose(tempfh); + + // Test BOM-less utf8 + tempfh = fopen(tempfile, "wb"); + ok(tempfh != NULL, "can't open tempfile\n"); + ret = WideCharToMultiByte(CP_UTF8, 0, wchar_text + 1, ARRAY_SIZE(wchar_text) - 1, + utf8_text, sizeof(utf8_text), NULL, NULL); + utf8_text[ret] = '\0'; + ok(ret > 0, "utf-8 conversion failed\n"); + fwrite(utf8_text, sizeof(char), ret, tempfh); + fclose(tempfh); + + // ccs=utf-8 interprets BOM-less content correctly + tempfh = fopen(tempfile, "rt, ccs=UTF-8"); + ok(tempfh != NULL, "can't open tempfile\n"); + for (i = 1; i < ARRAY_SIZE(wchar_text); i++) + { + ch = fgetwc(tempfh); + ok(ch == wchar_text[i], + "got %04hx, expected %04x (utf8[%d])\n", ch, wchar_text[i], i-1); + } + ch = fgetwc(tempfh); + ok(ch == WEOF, "got %04hx, expected WEOF (utf8)\n", ch); + fclose(tempfh); + + // ccs=unicode without a BOM only returns raw bytes + tempfh = fopen(tempfile, "rt, ccs=unicode"); + ok(tempfh != NULL, "can't open tempfile\n"); + for (i = 0; utf8_text[i]; i++) + { + ch = fgetwc(tempfh); + ok(ch == (unsigned char) utf8_text[i], + "got %04hx, expected %04x (unicode[%d])\n", ch, (unsigned char)utf8_text[i], i); + } + ch = fgetwc(tempfh); + ok(ch == WEOF, "got %04hx, expected WEOF (unicode)\n", ch); + fclose(tempfh); + unlink(temppath); }
Hi Martin,
I've sent a changed version of your patch. I hope it looks good for you.
Thanks, Piotr
Hi Piotr,
On Wed, 27 Jan 2021, Piotr Caban wrote:
I've sent a changed version of your patch. I hope it looks good for you.
Thanks! Sorry I always forget about not using C99 style comments - I don't mind them removed if you (who most probably is the one going to poke around in the test later) don't want them littering the test code. For the functional change I don't have much input - if it fixes the testcase I'm happy at least :-)
// Martin