diff options
Diffstat (limited to '')
-rw-r--r-- | misc/bstr.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/bstr.c b/misc/bstr.c index 4f1e862..abe688b 100644 --- a/misc/bstr.c +++ b/misc/bstr.c @@ -467,3 +467,23 @@ bool bstr_decode_hex(void *talloc_ctx, struct bstr hex, struct bstr *out) *out = (struct bstr){ .start = arr, .len = len }; return true; } + +#ifdef _WIN32 + +#include <windows.h> + +int bstr_to_wchar(void *talloc_ctx, struct bstr s, wchar_t **ret) +{ + int count = MultiByteToWideChar(CP_UTF8, 0, s.start, s.len, NULL, 0); + if (count <= 0) + abort(); + wchar_t *wbuf = *ret; + if (!wbuf || ta_get_size(wbuf) < (count + 1) * sizeof(wchar_t)) + wbuf = talloc_realloc(talloc_ctx, wbuf, wchar_t, count + 1); + MultiByteToWideChar(CP_UTF8, 0, s.start, s.len, wbuf, count); + wbuf[count] = L'\0'; + *ret = wbuf; + return count; +} + +#endif |