3 #if defined(__CYGWIN__) || defined(__WIN32__)
9 #include "wimlib_internal.h"
12 #ifdef ENABLE_ERROR_MESSAGES
13 void win32_error(u32 err_code)
17 nchars = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
19 (char*)&buffer, 0, NULL);
21 ERROR("Error printing error message! "
22 "Computer will self-destruct in 3 seconds.");
24 ERROR("Win32 error: %s", buffer);
29 #define win32_error(err_code)
32 void *win32_open_file_readonly(const void *path)
34 return CreateFileW((const wchar_t*)path,
36 FILE_READ_ATTRIBUTES |
38 ACCESS_SYSTEM_SECURITY,
40 NULL, /* lpSecurityAttributes */
42 FILE_FLAG_BACKUP_SEMANTICS |
43 FILE_FLAG_OPEN_REPARSE_POINT,
44 NULL /* hTemplateFile */);
47 int win32_read_file(const char *filename,
48 void *handle, u64 offset, size_t size, u8 *buf)
53 LARGE_INTEGER liOffset = {.QuadPart = offset};
55 wimlib_assert(size <= 0xffffffff);
57 if (SetFilePointerEx(h, liOffset, NULL, FILE_BEGIN))
58 if (ReadFile(h, buf, size, &bytesRead, NULL) && bytesRead == size)
61 ERROR("Error reading \"%s\"", filename);
63 return WIMLIB_ERR_READ;
66 void win32_close_file(void *handle)
68 CloseHandle((HANDLE)handle);
71 #endif /* __CYGWIN__ || __WIN32__ */