#include <assert.h>
#include <stdio.h>
-/* Replacement for glob() in Windows native builds. */
+/* Replacement for glob() in Windows native builds that operates on wide
+ * characters. */
int
win32_wglob(const wchar_t *pattern, int flags,
int (*errfunc)(const wchar_t *epath, int eerrno),
size_t filename_len = wcslen(dat.cFileName);
size_t len_needed = prefix_len + filename_len;
- path = malloc(len_needed + sizeof(wchar_t));
+ path = malloc((len_needed + 1) * sizeof(wchar_t));
if (!path)
goto oom;
}
static bool
-win32_modify_privilege(const char *privilege, bool enable)
+win32_modify_privilege(const wchar_t *privilege, bool enable)
{
HANDLE hToken;
LUID luid;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken))
- {
goto out;
- }
- if (!LookupPrivilegeValue(NULL, privilege, &luid)) {
+ if (!LookupPrivilegeValueW(NULL, privilege, &luid))
goto out;
- }
newState.PrivilegeCount = 1;
newState.Privileges[0].Luid = luid;
win32_modify_restore_privileges(false);
}
+/* Convert a string from the "current Windows codepage" to UTF-16LE. */
wchar_t *
win32_mbs_to_wcs(const char *mbs, size_t mbs_nbytes, size_t *num_wchars_ret)
{
return c == L'/' || c == L'\\';
}
+/* basename() (modifying, trailing-slash stripping version) for wide-character
+ * strings. */
wchar_t *
win32_wbasename(wchar_t *path)
{