X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwin32_common.c;h=412421ea28ce1480cb56bcea651c2b6896e038e4;hp=7016fe2a6c3d5644f29cdac1f995b9398b8486ed;hb=aae154ad67444bc760bedff60bc60fd5b91b8ede;hpb=e9aed5bf5c3296f35ff7007cb1702c07b7dc2b37 diff --git a/src/win32_common.c b/src/win32_common.c index 7016fe2a..412421ea 100644 --- a/src/win32_common.c +++ b/src/win32_common.c @@ -622,4 +622,42 @@ win32_global_cleanup(void) cleanup_dll(&ntdll_spec); } +/* + * Translates a Win32-namespace path into an NT-namespace path. + * + * On success, returns 0. The NT-namespace path will be stored in the + * UNICODE_STRING structure pointed to by nt_path. nt_path->Buffer will be set + * to a new buffer that must later be freed with HeapFree(). (Really + * RtlHeapFree(), but HeapFree() seems to be the same thing.) + * + * On failure, returns WIMLIB_ERR_NOMEM or WIMLIB_ERR_INVALID_PARAM. + */ +int +win32_path_to_nt_path(const wchar_t *win32_path, UNICODE_STRING *nt_path) +{ + NTSTATUS status; + + if (func_RtlDosPathNameToNtPathName_U_WithStatus) { + status = (*func_RtlDosPathNameToNtPathName_U_WithStatus)(win32_path, + nt_path, + NULL, NULL); + } else { + if ((*func_RtlDosPathNameToNtPathName_U)(win32_path, nt_path, + NULL, NULL)) + status = STATUS_SUCCESS; + else + status = STATUS_NO_MEMORY; + } + + if (likely(NT_SUCCESS(status))) + return 0; + + if (status == STATUS_NO_MEMORY) + return WIMLIB_ERR_NOMEM; + + ERROR("\"%ls\": invalid path name (status=0x%08"PRIx32")", + win32_path, (u32)status); + return WIMLIB_ERR_INVALID_PARAM; +} + #endif /* __WIN32__ */