utf8_to_utf16: align with libuv

- take a size parameter
- always NUL-terminate the result
- return libuv error code
- handle error in caller only (avoid redundant messages)

53995a3825
4c945f4936
This commit is contained in:
Justin M. Keyes
2019-08-13 05:47:58 +02:00
parent fc60d92795
commit 8727f7a6a4
4 changed files with 47 additions and 51 deletions

View File

@@ -2559,10 +2559,11 @@ static int do_more_prompt(int typed_char)
#if defined(WIN32)
void mch_errmsg(char *str)
{
assert(str != NULL);
wchar_t *utf16str;
int conversion_result = utf8_to_utf16((str), &utf16str);
if (conversion_result != 0) {
EMSG2("utf8_to_utf16 failed: %d", conversion_result);
int r = utf8_to_utf16(str, -1, &utf16str);
if (r != 0) {
fprintf(stderr, "utf8_to_utf16 failed: %d", r);
} else {
fwprintf(stderr, L"%ls", utf16str);
xfree(utf16str);
@@ -2572,10 +2573,11 @@ void mch_errmsg(char *str)
// Give a message. To be used when the UI is not initialized yet.
void mch_msg(char *str)
{
assert(str != NULL);
wchar_t *utf16str;
int conversion_result = utf8_to_utf16((str), &utf16str);
if (conversion_result != 0) {
EMSG2("utf8_to_utf16 failed: %d", conversion_result);
int r = utf8_to_utf16(str, -1, &utf16str);
if (r != 0) {
fprintf(stderr, "utf8_to_utf16 failed: %d", r);
} else {
wprintf(L"%ls", utf16str);
xfree(utf16str);