diff options
Diffstat (limited to 'src/win32/environment_win32.c')
-rw-r--r-- | src/win32/environment_win32.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/win32/environment_win32.c b/src/win32/environment_win32.c index 64feee5..ce5f00e 100644 --- a/src/win32/environment_win32.c +++ b/src/win32/environment_win32.c @@ -1,6 +1,8 @@ // Copyright 2012-2024 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC +#include "win32_util.h" + #include <zix/environment.h> #include <windows.h> @@ -9,14 +11,27 @@ char* zix_expand_environment_strings(ZixAllocator* const allocator, const char* const string) { - const DWORD size = ExpandEnvironmentStrings(string, NULL, 0U); + ArgPathChar* const wstring = arg_path_new(allocator, string); + + const DWORD size = ExpandEnvironmentStrings(wstring, NULL, 0U); if (!size) { + arg_path_free(allocator, wstring); return NULL; } - char* const out = (char*)zix_calloc(allocator, (size_t)size + 1U, 1U); + TCHAR* const out = + (TCHAR*)zix_calloc(allocator, (size_t)size + 1U, sizeof(TCHAR)); if (out) { - ExpandEnvironmentStrings(string, out, size + 1U); + ExpandEnvironmentStrings(wstring, out, size + 1U); } + + arg_path_free(allocator, wstring); + +#ifdef UNICODE + char* const result = zix_wchar_to_utf8(allocator, out); + zix_free(allocator, out); + return result; +#else return out; +#endif } |