1 /* Windows-specific code for wimlib-imagex. */
4 # error "This file contains Windows code"
7 #include "imagex-win32.h"
13 /* Convert a string from the "current Windows codepage" to UTF-16LE. */
15 win32_mbs_to_wcs(const char *mbs, size_t mbs_nbytes, size_t *num_wchars_ret)
17 if (mbs_nbytes > INT_MAX) {
18 fwprintf(stderr, L"ERROR: too much data (%zu bytes)!\n",
22 if (mbs_nbytes == 0) {
26 int len = MultiByteToWideChar(CP_ACP,
34 wchar_t *wcs = malloc(len * sizeof(wchar_t));
36 fwprintf(stderr, L"ERROR: out of memory!\n");
39 int len2 = MultiByteToWideChar(CP_ACP,
49 *num_wchars_ret = len;
53 L"ERROR: Invalid multi-byte string in the text file you provided as input!\n"
54 L" Maybe try converting your text file to UTF-16LE?\n"
60 is_path_separator(wchar_t c)
62 return c == L'/' || c == L'\\';
65 /* basename() (modifying, trailing-slash stripping version) for wide-character
66 * strings. Understands both forward and backward slashes. */
68 win32_wbasename(wchar_t *path)
70 wchar_t *p = wcschr(path, L'\0');
73 while (p >= path && is_path_separator(*p))
75 while (p >= path && !is_path_separator(*p))
81 /* Set a file descriptor to binary mode. */
82 void set_fd_to_binary_mode(int fd)
84 _setmode(fd, _O_BINARY);
90 get_security_descriptor_string(PSECURITY_DESCRIPTOR desc)
93 /* 53 characters!!! */
94 ConvertSecurityDescriptorToStringSecurityDescriptorW(
97 OWNER_SECURITY_INFORMATION |
98 GROUP_SECURITY_INFORMATION |
99 DACL_SECURITY_INFORMATION |
100 SACL_SECURITY_INFORMATION,
107 win32_print_security_descriptor(const uint8_t *sd, size_t size)
110 const wchar_t *printstr;
112 /* 'size' is ignored here due to the crappy Windows APIs. Oh well, this
113 * is just for debugging anyway. */
114 str = get_security_descriptor_string((PSECURITY_DESCRIPTOR)sd);
118 printstr = L"(invalid)";
120 wprintf(L"Security Descriptor = %ls\n", printstr);