4 #include <winpr/file.h>
5 #include <winpr/path.h>
6 #include <winpr/handle.h>
7 #include <winpr/windows.h>
8 #include <winpr/sysinfo.h>
10 int TestFileCreateFile(
int argc,
char* argv[])
15 const char buffer[] =
"Some random text\r\njust want it done.";
16 char cmp[
sizeof(buffer)];
20 SYSTEMTIME systemTime;
23 GetSystemTime(&systemTime);
24 (void)sprintf_s(sname,
sizeof(sname),
25 "CreateFile-%04" PRIu16
"%02" PRIu16
"%02" PRIu16
"%02" PRIu16
"%02" PRIu16
26 "%02" PRIu16
"%04" PRIu16,
27 systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
28 systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds);
29 name = GetKnownSubPath(KNOWN_PATH_TEMP, sname);
36 hr = PathCchConvertStyleA(name, strlen(name), PATH_STYLE_UNIX);
41 handle = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW,
42 FILE_ATTRIBUTE_NORMAL, NULL);
50 if (!winpr_PathFileExists(name))
53 if (!WriteFile(handle, buffer,
sizeof(buffer), &written, NULL))
56 if (written !=
sizeof(buffer))
59 written = SetFilePointer(handle, 5, NULL, FILE_BEGIN);
64 written = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
69 written = SetFilePointer(handle, -5, NULL, FILE_CURRENT);
74 if (!ReadFile(handle, cmp,
sizeof(cmp), &written, NULL))
77 if (written !=
sizeof(cmp))
80 if (memcmp(buffer, cmp,
sizeof(buffer)) != 0)
83 if (!CloseHandle(handle))
86 if (!winpr_DeleteFile(name))
89 if (winpr_PathFileExists(name))