summaryrefslogtreecommitdiffstats
path: root/misc/bstr.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:13:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:13:14 +0000
commit5a3b54c78ce63d899f76dbb3db72e4894b40bd53 (patch)
tree50693d13eeefc4d683bdf5417f0861b0ef274a0c /misc/bstr.c
parentAdding debian version 0.37.0-1. (diff)
downloadmpv-5a3b54c78ce63d899f76dbb3db72e4894b40bd53.tar.xz
mpv-5a3b54c78ce63d899f76dbb3db72e4894b40bd53.zip
Merging upstream version 0.38.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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 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