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@lyncon.se>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Ted Lyngmo 2021-10-11 16:15:39 +02:00 committed by Alexandre Julliard
parent bb637469e1
commit 51b9f4cd2b
2 changed files with 56 additions and 0 deletions

View File

@ -1586,6 +1586,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;

View File

@ -1539,6 +1539,54 @@ static void test_fenv(void)
ok(!except, "expected 0, got %lx\n", except);
}
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;
@ -1580,4 +1628,5 @@ START_TEST(misc)
test_clock();
test_thread_storage();
test_fenv();
test_fopen_exclusive();
}