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
commit60e8a3d404f0640fa5a3f834eae54b4f1fb9127d (patch)
tree1da89a218d0ecf010c67a87cb2f625c4cb18e7d7 /misc/bstr.c
parentAdding upstream version 0.37.0. (diff)
downloadmpv-upstream.tar.xz
mpv-upstream.zip
Adding upstream version 0.38.0.upstream/0.38.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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