win32.c (1041B)
1 #define WIN32_LEAN_AND_MEAN 2 #include <windows.h> 3 4 #define OS_READ GENERIC_READ 5 #define OS_WRITE GENERIC_WRITE 6 #define OS_RW (GENERIC_READ | GENERIC_WRITE) 7 #define OS_SEEK_BEG FILE_BEGIN 8 #define OS_SEEK_CUR FILE_CURRENT 9 #define OS_SEEK_END FILE_END 10 11 typedef HANDLE os_file; 12 13 static os_file 14 os_open(s8 path, int flags) 15 { 16 os_file f; 17 f = CreateFileA((char *)path.data, flags, 0, NULL, 18 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 19 if (f == INVALID_HANDLE_VALUE) 20 die("rip can't open output file: %s\n", path.data); 21 return f; 22 } 23 24 static void 25 os_write(os_file f, s8 s) 26 { 27 if (WriteFile(f, s.data, s.len, 0, 0) == 0) 28 die("can't write to file\n"); 29 } 30 31 static void 32 os_close(os_file f) 33 { 34 CloseHandle(f); 35 } 36 37 static void 38 os_seek(os_file f, size off, int whence) 39 { 40 SetFilePointer(f, off, 0, whence); 41 } 42 43 static u32 44 os_get_core_count(void) 45 { 46 SYSTEM_INFO sysinfo; 47 GetSystemInfo(&sysinfo); 48 return sysinfo.dwNumberOfProcessors; 49 } 50 51 static void 52 os_pause(void) 53 { 54 fputs("Press any key to close...", stdout); 55 fgetc(stdin); 56 }