42 int n = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
43 WCHAR *ucs16 =
gc_malloc(n *
sizeof(WCHAR),
false,
gc);
44 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, ucs16, n);
52 int n = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, NULL, NULL);
58 WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, n, NULL, NULL);
75cmp_prefix(
const char *str,
const bool n,
const char *pre)
86 const int c1 = pre[i];
102 return c2 ==
'\0' || c2 ==
'.';
108 if (c1 != tolower(c2))
152 static char tmpdir[MAX_PATH];
153 WCHAR wtmpdir[MAX_PATH];
155 if (!GetTempPathW(_countof(wtmpdir), wtmpdir))
160 int ret = WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL);
167 if ((
unsigned int)ret >
sizeof(tmpdir))
169 msg(
M_WARN,
"Could not get temporary directory. Path is too long."
170 " Consider using --tmp-dir");
174 WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, tmpdir,
sizeof(tmpdir), NULL, NULL);
181 size_t dir_len = wcslen(dir);
185 if (dir_len <= 1 || wcsnicmp(dir, path, dir_len) != 0)
195 if (dir[dir_len - 1] == L
'\\' || dir[dir_len - 1] == L
'/')
200 WCHAR next = path[dir_len];
201 return next == L
'\\' || next == L
'/';
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Garbage collection arena used to keep track of dynamically allocated memory.
bool win_path_in_dir(const WCHAR *path, const WCHAR *dir)
Check whether path resides within directory dir.
char * utf16to8(const wchar_t *utf16, struct gc_arena *gc)
static bool cmp_prefix(const char *str, const bool n, const char *pre)
bool win_safe_filename(const char *fn)
const char * win_get_tempdir(void)
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)