This fixes bug 51846: Standard library call fopen(..., "wx") not recognized - causes destruction of data.
Signed-off-by: Ted Lyngmo ted@lyncon.se --- dlls/msvcrt/file.c | 3 +++ dlls/msvcrt/tests/file.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index b0eeaf2a351..355638fa783 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1586,6 +1586,9 @@ static int msvcrt_get_flags(const wchar_t* mode, int *open_flags, int* stream_fl *open_flags |= _O_TEXT; *open_flags &= ~_O_BINARY; break; + case 'x': + *open_flags |= _O_EXCL; + break; case 'D': *open_flags |= _O_TEMPORARY; break; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 1d74c6135b8..3b96be58126 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -110,6 +110,32 @@ static void test_filbuf( void ) unlink("filbuf.tst"); }
+static void test_fopen_exclusive( void ) +{ + static const char * const testfile = "fileexcl.tst"; + FILE *fp; + + fp = fopen(testfile, "wx"); + ok(fp != NULL, "creating file with mode wx failed\n"); + if(fp) fclose(fp); + + fp = fopen(testfile, "wx"); + ok(fp == NULL, "overwrote existing file with mode wx\n"); + if(fp) fclose(fp); + + unlink(testfile); + + fp = fopen(testfile, "w+x"); + ok(fp != NULL, "creating file with mode w+x failed\n"); + if(fp) fclose(fp); + + fp = fopen(testfile, "w+x"); + ok(fp == NULL, "overwrote existing file with mode w+x\n"); + if(fp) fclose(fp); + + unlink(testfile); +} + static void test_fdopen( void ) { static const char buffer[] = {0,1,2,3,4,5,6,7,8,9}; @@ -2841,6 +2867,7 @@ START_TEST(file)
/* testing stream I/O */ test_filbuf(); + test_fopen_exclusive(); test_fdopen(); test_fopen_fclose_fcloseall(); test_fopen_s();