summaryrefslogtreecommitdiffstats
path: root/src/win32/environment_win32.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-12-10 22:22:44 -0500
committerDavid Robillard <d@drobilla.net>2024-12-11 00:22:12 -0500
commite41951c43a8f6a0bcf6b0fcceebec99f87f7d1e7 (patch)
tree20be9e945e56acedc3d91c4a36f0c36fab5bb05f /src/win32/environment_win32.c
parentba2c2a08973cb5eae1feabbb9431c897cded03f6 (diff)
downloadzix-e41951c43a8f6a0bcf6b0fcceebec99f87f7d1e7.tar.gz
zix-e41951c43a8f6a0bcf6b0fcceebec99f87f7d1e7.tar.bz2
zix-e41951c43a8f6a0bcf6b0fcceebec99f87f7d1e7.zip
Support building for Windows with or without UNICODE
Diffstat (limited to 'src/win32/environment_win32.c')
-rw-r--r--src/win32/environment_win32.c21
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
}