Ted Lyngmo : ucrtbase: Add support for x mode in fopen.
Module: wine Branch: oldstable Commit: b690f67231aa4c444ed5d102f1d16c4300850274 URL: https://source.winehq.org/git/wine.git/?a=commit;h=b690f67231aa4c444ed5d102f... Author: Ted Lyngmo <ted(a)lyncon.se> Date: Mon Oct 11 16:15:39 2021 +0200 ucrtbase: Add support for x mode in fopen. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51846 Signed-off-by: Ted Lyngmo <ted(a)lyncon.se> Signed-off-by: Piotr Caban <piotr(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> (cherry picked from commit 51b9f4cd2b7faa04d5bfd50dfe9a4382e0b76fc6) Conflicts: dlls/ucrtbase/tests/misc.c Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org> --- dlls/msvcrt/file.c | 7 +++++++ dlls/ucrtbase/tests/misc.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 91d4f11007c..36b1d637a27 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1588,6 +1588,13 @@ static int msvcrt_get_flags(const wchar_t* mode, int *open_flags, int* stream_fl *open_flags |= _O_TEXT; *open_flags &= ~_O_BINARY; break; +#if _MSVCR_VER>=140 + case 'x': + if(!MSVCRT_CHECK_PMT((*open_flags & (_O_CREAT | _O_APPEND)) == _O_CREAT)) + return -1; + *open_flags |= _O_EXCL; + break; +#endif case 'D': *open_flags |= _O_TEMPORARY; break; diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 5fcec2e2bb5..8dc1a1b2f8e 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -1371,6 +1371,54 @@ static void test_thread_storage(void) "can't find se_translator in thread storage\n"); } +static void test_fopen_exclusive( void ) +{ + char path[MAX_PATH*2]; + DWORD len; + FILE *fp; + + if (!GetProcAddress(GetModuleHandleA("ucrtbase.dll"), "__std_terminate")) + { + win_skip("skipping fopen x mode tests.\n"); + return; + } + + len = GetTempPathA(MAX_PATH, path); + ok(len, "GetTempPathA failed\n"); + strcat(path, "\\fileexcl.tst"); + + fp = fopen(path, "wx"); + ok(fp != NULL, "creating file with mode wx failed\n"); + fclose(fp); + + fp = fopen(path, "wx"); + ok(!fp, "overwrote existing file with mode wx\n"); + unlink(path); + + fp = fopen(path, "w+x"); + ok(fp != NULL, "creating file with mode w+x failed\n"); + fclose(fp); + + fp = fopen(path, "w+x"); + ok(!fp, "overwrote existing file with mode w+x\n"); + + SET_EXPECT(global_invalid_parameter_handler); + fp = fopen(path, "rx"); + CHECK_CALLED(global_invalid_parameter_handler); + ok(!fp, "opening file with mode rx succeeded\n"); + unlink(path); + + SET_EXPECT(global_invalid_parameter_handler); + fp = fopen(path, "xw"); + CHECK_CALLED(global_invalid_parameter_handler); + ok(!fp, "creating file with mode xw succeeded\n"); + + fp = fopen(path, "wbx"); + ok(fp != NULL, "creating file with mode wx failed\n"); + fclose(fp); + unlink(path); +} + START_TEST(misc) { int arg_c; @@ -1411,4 +1459,5 @@ START_TEST(misc) test__o_malloc(); test_clock(); test_thread_storage(); + test_fopen_exclusive(); }
participants (1)
-
Alexandre Julliard