mesa/src/util/u_string.c
Yonggang Luo 723eeac89b
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
util: Refactoring util_dl_get_path_from_proc out of clc/clc_helpers.cpp
For getting clc_helpers.cpp can be compiled with gcc/mingw

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36597>
2025-08-07 21:15:13 +00:00

35 lines
807 B
C

/*
* Copyright 2022 Yonggang Luo
* SPDX-License-Identifier: MIT
*
* String utils
*/
#include "util/u_string.h"
#if DETECT_OS_WINDOWS
#include <windows.h>
#endif
#if DETECT_OS_WINDOWS
static char *
strdup_wstr_codepage(unsigned codepage, const wchar_t *utf16_str)
{
if (!utf16_str)
return NULL;
const int multi_byte_length = WideCharToMultiByte(codepage, 0, utf16_str, -1, NULL,
0, NULL, NULL);
char* multi_byte = malloc(multi_byte_length + 1);
WideCharToMultiByte(codepage, 0, utf16_str, -1, multi_byte, multi_byte_length, NULL,
NULL);
multi_byte[multi_byte_length] = 0;
return multi_byte;
}
char *
strdup_wstr_utf8(const wchar_t *wstr)
{
return strdup_wstr_codepage(CP_UTF8, wstr);
}
#endif