summaryrefslogtreecommitdiffstats
path: root/misc/bstr.c
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-03-17 12:54:06 +0100
committerKacper Michajłow <kasper93@gmail.com>2024-03-19 19:58:09 +0100
commit2ee0db4c5dbf1a5d956fc4a338781b48e812c85b (patch)
tree345971bfbb1e9355a6381a7f149d45e21168731c /misc/bstr.c
parentc1282d4d43be8fb8bbc8529b22804d288d59038a (diff)
downloadmpv-2ee0db4c5dbf1a5d956fc4a338781b48e812c85b.tar.bz2
mpv-2ee0db4c5dbf1a5d956fc4a338781b48e812c85b.tar.xz
misc/bstr: add bstr_to_wchar for win32
Convenience to avoid strlen above other things.
Diffstat (limited to 'misc/bstr.c')
-rw-r--r--misc/bstr.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/bstr.c b/misc/bstr.c
index 4f1e8629b3..abe688bd14 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