From 4833aebbdd933a32d9e7ca7a8387ae4cc440b8ca Mon Sep 17 00:00:00 2001 From: Robert van Herk Date: Mon, 27 Feb 2012 11:10:03 +0100 Subject: Windows fopen has some fancy file modes 'T' and 'D'. Currently, wine wrongly interprets 'T' as 't'. They should be interpreted differently though: 't' is text file, and 'T' is temporary file. I've fixed this, and added a conformance test. modified: dlls/msvcrt/file.c modified: dlls/msvcrt/tests/file.c --- dlls/msvcrt/file.c | 8 +++++++- dlls/msvcrt/tests/file.c | 37 +++++++++++++++++++++++++++++++++++++ diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index c15e33f..99ed3eb 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1268,10 +1268,16 @@ static int msvcrt_get_flags(const MSVCRT_wchar_t* mode, int *open_flags, int* st *open_flags |= MSVCRT__O_BINARY; *open_flags &= ~MSVCRT__O_TEXT; break; - case 'T': case 't': + case 't': *open_flags |= MSVCRT__O_TEXT; *open_flags &= ~MSVCRT__O_BINARY; break; + case 'D': + *open_flags |= MSVCRT__O_TEMPORARY; + break; + case 'T': + *open_flags |= MSVCRT__O_SHORT_LIVED; + break; case '+': case ' ': break; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index b9b904d..f17d7b4 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -434,6 +434,42 @@ static void test_asciimode2(void) unlink("ascii2.tst"); } +static void test_filemodeT(void) +{ + char DATA [] = {26, 't', 'e', 's' ,'t'}; + char DATA2 [100]; + char temppath[MAX_PATH]; + char tempfile[MAX_PATH]; + FILE* f; + size_t bytesWritten; + size_t bytesRead; + WIN32_FIND_DATA findData; + HANDLE h; + + GetTempPath (MAX_PATH, temppath); + GetTempFileName (temppath, "", 0, tempfile); + + f = fopen(tempfile, "w+bDT"); + bytesWritten = fwrite(DATA, 1, sizeof(DATA), f); + rewind(f); + bytesRead = fread(DATA2, 1, sizeof(DATA2), f); + fclose(f); + + ok (bytesRead == bytesWritten && bytesRead == sizeof(DATA), + "fopen file mode 'T' wrongly interpreted as 't'! Right interpretation is:\n\t'T' -> temporary\n\t't' -> translated.\n" + ); + + h = FindFirstFile(tempfile, &findData); + + ok (h == INVALID_HANDLE_VALUE, + "File was opened in 'D' mode, but wasn't deleted when closed.\n" + ); + + if (h != INVALID_HANDLE_VALUE) { + FindClose(h); + } +} + static WCHAR* AtoW( const char* p ) { WCHAR* buffer; @@ -1576,6 +1612,7 @@ START_TEST(file) test_fileops(); test_asciimode(); test_asciimode2(); + test_filemodeT(); test_readmode(FALSE); /* binary mode */ test_readmode(TRUE); /* ascii mode */ test_readboundary(); -- 1.7.4.4