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);