-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_file_cdrive.c
More file actions
57 lines (45 loc) · 1.37 KB
/
test_file_cdrive.c
File metadata and controls
57 lines (45 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* test_file_cdrive.c - Test C: drive mapping
*
* Compile with: x86_64-w64-mingw32-gcc -o test_file_cdrive.exe test_file_cdrive.c
*/
#include <windows.h>
#include <stdio.h>
int main(void)
{
HANDLE hFile;
DWORD written;
const char* data = "Hello from C: drive!\n";
BOOL result;
printf("LSW C: Drive Test\n");
printf("==================\n\n");
/* Create file on C: drive */
printf("Creating C:\\test.txt...\n");
hFile = CreateFileA("C:\\test.txt",
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("ERROR: Failed to create file!\n");
return 1;
}
printf("File created, handle: 0x%p\n", hFile);
/* Write data */
printf("Writing data...\n");
result = WriteFile(hFile, data, (DWORD)strlen(data), &written, NULL);
if (!result) {
printf("ERROR: WriteFile failed!\n");
CloseHandle(hFile);
return 1;
}
printf("Wrote %lu bytes\n", written);
/* Close file */
printf("Closing file...\n");
CloseHandle(hFile);
printf("\n=== SUCCESS ===\n");
printf("C:\\test.txt should exist at: ~/.lsw/drives/c/test.txt\n");
return 0;
}