remove trailing whitespace at end of lines
[reactos.git] / rosapps / tests / sectest / sectest.c
1 /* $Id$ */
2 #define UNICODE
3 #define _UNICODE
4 #include <windows.h>
5 #include <stdio.h>
6 #include <string.h>
7
8 int main(int argc, char* argv[])
9 {
10 HANDLE hFile;
11 HANDLE Section;
12 PVOID BaseAddress;
13
14 printf("Section Test\n");
15
16 hFile = CreateFile(_T("sectest.txt"),
17 GENERIC_READ | GENERIC_WRITE,
18 0,
19 NULL,
20 CREATE_ALWAYS,
21 0,
22 0);
23 if (hFile == INVALID_HANDLE_VALUE)
24 {
25 printf("Failed to create file (err=%ld)", GetLastError());
26 return 1;
27 }
28
29 Section = CreateFileMapping(hFile,
30 NULL,
31 PAGE_READWRITE,
32 0,
33 4096,
34 NULL);
35 if (Section == NULL)
36 {
37 printf("Failed to create section (err=%ld)", GetLastError());
38 return 1;
39 }
40
41 printf("Mapping view of section\n");
42 BaseAddress = MapViewOfFile(Section,
43 FILE_MAP_ALL_ACCESS,
44 0,
45 0,
46 4096);
47 printf("BaseAddress %x\n", (UINT) BaseAddress);
48 if (BaseAddress == NULL)
49 {
50 printf("Failed to map section (%ld)\n", GetLastError());
51 return 1;
52 }
53
54 printf("Clearing section\n");
55 FillMemory(BaseAddress, 4096, ' ');
56 printf("Copying test data to section\n");
57 strcpy(BaseAddress, "test data");
58
59 if (!UnmapViewOfFile(BaseAddress))
60 {
61 printf("Failed to unmap view of file (%ld)\n", GetLastError());
62 return 1;
63 }
64
65 if (!CloseHandle(hFile))
66 {
67 printf("Failed to close file (%ld)\n", GetLastError());
68 return 1;
69 }
70
71 return 0;
72 }
73