-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_readwrite_full.c
More file actions
54 lines (46 loc) · 1.53 KB
/
test_readwrite_full.c
File metadata and controls
54 lines (46 loc) · 1.53 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
/*
* test_readwrite_full.c - Test file read/write cycle
*/
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
HANDLE hFile;
DWORD written, bytesRead;
const char* write_data = "LSW Read/Write Test!\n";
char read_buffer[256];
BOOL result;
printf("LSW Read/Write Cycle Test\n");
printf("==========================\n\n");
/* WRITE */
printf("Step 1: Writing file...\n");
hFile = CreateFileA("C:\\readtest.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("ERROR: Create failed!\n");
return 1;
}
WriteFile(hFile, write_data, (DWORD)strlen(write_data), &written, NULL);
printf("Wrote %lu bytes\n", written);
CloseHandle(hFile);
/* READ */
printf("\nStep 2: Reading file...\n");
hFile = CreateFileA("C:\\readtest.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("ERROR: Open failed!\n");
return 1;
}
memset(read_buffer, 0, sizeof(read_buffer));
ReadFile(hFile, read_buffer, sizeof(read_buffer) - 1, &bytesRead, NULL);
printf("Read %lu bytes\n", bytesRead);
printf("Data: '%s'\n", read_buffer);
CloseHandle(hFile);
/* VERIFY */
if (strcmp(read_buffer, write_data) == 0) {
printf("\n✅ SUCCESS! Read/Write cycle works!\n");
return 0;
} else {
printf("\n❌ FAILURE! Data mismatch!\n");
return 1;
}
}