]> wimlib.net Git - wimlib/blobdiff - programs/imagex-win32.c
Fix problem where HAVE_NTFS_MNT_RDONLY would not get defined
[wimlib] / programs / imagex-win32.c
index 18581ed0d2603bd94442c18d2814372d7008b4cb..9e93c4cc8510cf9b27931d6358918e6b610facb6 100644 (file)
@@ -14,7 +14,8 @@
 #include <assert.h>
 #include <stdio.h>
 
 #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),
 int
 win32_wglob(const wchar_t *pattern, int flags,
            int (*errfunc)(const wchar_t *epath, int eerrno),
@@ -80,7 +81,7 @@ win32_wglob(const wchar_t *pattern, int flags,
                size_t filename_len = wcslen(dat.cFileName);
                size_t len_needed = prefix_len + filename_len;
 
                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;
 
                if (!path)
                        goto oom;
 
@@ -119,7 +120,7 @@ globfree(glob_t *pglob)
 }
 
 static bool
 }
 
 static bool
-win32_modify_privilege(const char *privilege, bool enable)
+win32_modify_privilege(const wchar_t *privilege, bool enable)
 {
        HANDLE hToken;
        LUID luid;
 {
        HANDLE hToken;
        LUID luid;
@@ -129,13 +130,10 @@ win32_modify_privilege(const char *privilege, bool enable)
        if (!OpenProcessToken(GetCurrentProcess(),
                              TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                              &hToken))
        if (!OpenProcessToken(GetCurrentProcess(),
                              TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                              &hToken))
-       {
                goto out;
                goto out;
-       }
 
 
-       if (!LookupPrivilegeValue(NULL, privilege, &luid)) {
+       if (!LookupPrivilegeValueW(NULL, privilege, &luid))
                goto out;
                goto out;
-       }
 
        newState.PrivilegeCount = 1;
        newState.Privileges[0].Luid = luid;
 
        newState.PrivilegeCount = 1;
        newState.Privileges[0].Luid = luid;
@@ -171,29 +169,30 @@ win32_modify_restore_privileges(bool enable)
 }
 
 void
 }
 
 void
-win32_acquire_capture_privileges()
+win32_acquire_capture_privileges(void)
 {
        win32_modify_capture_privileges(true);
 }
 
 void
 {
        win32_modify_capture_privileges(true);
 }
 
 void
-win32_release_capture_privileges()
+win32_release_capture_privileges(void)
 {
        win32_modify_capture_privileges(false);
 }
 
 void
 {
        win32_modify_capture_privileges(false);
 }
 
 void
-win32_acquire_restore_privileges()
+win32_acquire_restore_privileges(void)
 {
        win32_modify_restore_privileges(true);
 }
 
 void
 {
        win32_modify_restore_privileges(true);
 }
 
 void
-win32_release_restore_privileges()
+win32_release_restore_privileges(void)
 {
        win32_modify_restore_privileges(false);
 }
 
 {
        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)
 {
 wchar_t *
 win32_mbs_to_wcs(const char *mbs, size_t mbs_nbytes, size_t *num_wchars_ret)
 {
@@ -245,6 +244,8 @@ is_path_separator(wchar_t c)
        return c == L'/' || c == L'\\';
 }
 
        return c == L'/' || c == L'\\';
 }
 
+/* basename() (modifying, trailing-slash stripping version) for wide-character
+ * strings. */
 wchar_t *
 win32_wbasename(wchar_t *path)
 {
 wchar_t *
 win32_wbasename(wchar_t *path)
 {