From 5e34883f36cf60a40fdbd7f636119331ba989a41 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 1 Jul 2023 09:24:57 -0400 Subject: [PATCH] windows: more setlocale --- sys/windows/consoletty.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index 4e7d00963..f9b66aae2 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -1911,16 +1911,18 @@ tty_utf8graphics_fixup(void) { CONSOLE_FONT_INFOEX console_font_info; if ((tty_procs.wincap2 & WC2_U_UTF8STR) && SYMHANDLING(H_UTF8)) { - char *tmpstr = 0; + char *localestr = 0; - if (!console.hConOut) + if (!console.hConOut) console.hConOut = GetStdHandle(STD_OUTPUT_HANDLE); /* the locale */ - if (console.localestr) + if (console.localestr) { free(console.localestr); - tmpstr = setlocale(LC_ALL, ".UTF8"); - if (tmpstr) - console.localestr = dupstr(tmpstr); + console.localestr = NULL; + } + localestr = setlocale(LC_ALL, ".UTF8"); + if (localestr) + console.localestr = dupstr(localestr); /* the code page */ SetConsoleOutputCP(65001); console.code_page = GetConsoleOutputCP(); @@ -2510,7 +2512,10 @@ void nethack_enter_consoletty(void) console.orig_code_page = GetConsoleOutputCP(); /* store the original locale */ - console.orig_localestr = dupstr(setlocale(LC_ALL, "")); + console.orig_localestr = NULL; + localestr = setlocale(LC_ALL, ""); + if (localestr) + console.orig_localestr = dupstr(localestr); /* store the original font */ console.orig_font_info.cbSize = sizeof(console.orig_font_info);