1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 /*=============================================================
7 ** Source: createfilemapping_neg.c
9 ** Purpose: Negative test the CreateFileMapping API.
10 ** Call CreateFileMapping to create a unnamed
11 ** file-mapping object with PAGE_READONLY
12 ** protection and try to map a zero length file
16 **============================================================*/
20 int __cdecl main(int argc, char *argv[])
24 HANDLE FileMappingHandle;
26 WCHAR *lpFileName = NULL;
28 //Initialize the PAL environment
29 err = PAL_Initialize(argc, argv);
35 //conver string to a unicode one
36 lpFileName = convert("temp.txt");
39 //create a file and return the file handle
40 FileHandle = CreateFile(lpFileName,
45 FILE_ATTRIBUTE_ARCHIVE,
51 if(INVALID_HANDLE_VALUE == FileHandle)
53 Fail("Failed to call CreateFile to create a file\n");
56 //create a unnamed file-mapping object with file handle FileHandle
57 //and with PAGE_READONLY protection
58 //try to map a file which is zero length.
59 FileMappingHandle = CreateFileMapping(
60 FileHandle, //File Handle
62 PAGE_READONLY, //access protection
63 0, //high-order of object size
64 0, //low-orger of object size
65 NULL); //unnamed object
68 if(NULL != FileMappingHandle || ERROR_FILE_INVALID != GetLastError())
70 Trace("\nFailed to call CreateFileMapping API for a negative test!\n");
71 err = CloseHandle(FileHandle);
74 Fail("\nFailed to call CloseHandle API\n");
76 err = CloseHandle(FileMappingHandle);
79 Fail("\nFailed to call CloseHandle API\n");
84 //close the file handle
85 err = CloseHandle(FileHandle);
88 Fail("\nFailed to call CloseHandle API\n");