aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-03-17 13:20:53 +0000
committerRon Yorston <rmy@pobox.com>2023-03-17 13:20:53 +0000
commitcb50586aedc9725fb14dbb25263bba1598726037 (patch)
tree679fd1e914693d5c900243a780ab812e69a3f3ec
parent87e7e7b1e61caa87112e3cf6527b606086b6b688 (diff)
downloadbusybox-w32-cb50586aedc9725fb14dbb25263bba1598726037.tar.gz
busybox-w32-cb50586aedc9725fb14dbb25263bba1598726037.tar.bz2
busybox-w32-cb50586aedc9725fb14dbb25263bba1598726037.zip
win32: delay adjusting code page
Commit 93a63809f9 (win32: add support for the euro currency symbol) caused all invocations of busybox-w32 to change code page 850 to 858. This has been known to cause problems with fonts in PowerShell (GitHub issue #207). Delay changing the code page until an i/o operation is imminent. Instances of PowerShell started by the `drop` applet during ssh login thus no longer have their code page adjusted.
-rw-r--r--include/mingw.h1
-rw-r--r--libbb/appletlib.c4
-rw-r--r--win32/winansi.c13
3 files changed, 13 insertions, 5 deletions
diff --git a/include/mingw.h b/include/mingw.h
index 0ccced2a3..a94d90767 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -554,7 +554,6 @@ void qsort_string_vector_case(char **sv, unsigned count) FAST_FUNC;
554 554
555const char *get_busybox_exec_path(void); 555const char *get_busybox_exec_path(void);
556void init_winsock(void); 556void init_winsock(void);
557void init_codepage(void);
558 557
559int has_bat_suffix(const char *p); 558int has_bat_suffix(const char *p);
560int has_exe_suffix(const char *p); 559int has_exe_suffix(const char *p);
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 504c1f634..dacfbdd22 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1290,9 +1290,7 @@ int main(int argc UNUSED_PARAM, char **argv)
1290 break; 1290 break;
1291 } 1291 }
1292 } 1292 }
1293# if ENABLE_FEATURE_EURO 1293
1294 init_codepage();
1295# endif
1296 /* Ignore critical errors, such as calling GetVolumeInformation() on 1294 /* Ignore critical errors, such as calling GetVolumeInformation() on
1297 * a floppy or CDROM drive with no media. */ 1295 * a floppy or CDROM drive with no media. */
1298 SetErrorMode(SEM_FAILCRITICALERRORS); 1296 SetErrorMode(SEM_FAILCRITICALERRORS);
diff --git a/win32/winansi.c b/win32/winansi.c
index de6db08e2..dbdba9626 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -29,6 +29,10 @@
29static WORD plain_attr = 0xffff; 29static WORD plain_attr = 0xffff;
30static WORD current_attr; 30static WORD current_attr;
31 31
32#if ENABLE_FEATURE_EURO
33static void init_codepage(void);
34#endif
35
32static HANDLE get_console(void) 36static HANDLE get_console(void)
33{ 37{
34 return GetStdHandle(STD_OUTPUT_HANDLE); 38 return GetStdHandle(STD_OUTPUT_HANDLE);
@@ -75,6 +79,11 @@ int terminal_mode(int reset)
75{ 79{
76 static int mode = -1; 80 static int mode = -1;
77 81
82#if ENABLE_FEATURE_EURO
83 if (mode < 0)
84 init_codepage();
85#endif
86
78 if (mode < 0 || reset) { 87 if (mode < 0 || reset) {
79 HANDLE h; 88 HANDLE h;
80 DWORD oldmode, newmode; 89 DWORD oldmode, newmode;
@@ -699,7 +708,7 @@ static char *process_escape(char *pos)
699} 708}
700 709
701#if ENABLE_FEATURE_EURO 710#if ENABLE_FEATURE_EURO
702void init_codepage(void) 711static void init_codepage(void)
703{ 712{
704 if (GetConsoleCP() == 850 && GetConsoleOutputCP() == 850) { 713 if (GetConsoleCP() == 850 && GetConsoleOutputCP() == 850) {
705 SetConsoleCP(858); 714 SetConsoleCP(858);
@@ -715,6 +724,7 @@ static BOOL winansi_CharToOemBuff(LPCSTR s, LPSTR d, DWORD len)
715 if (!s || !d) 724 if (!s || !d)
716 return FALSE; 725 return FALSE;
717 726
727 terminal_mode(FALSE);
718 buf = xmalloc(len*sizeof(WCHAR)); 728 buf = xmalloc(len*sizeof(WCHAR));
719 MultiByteToWideChar(CP_ACP, 0, s, len, buf, len); 729 MultiByteToWideChar(CP_ACP, 0, s, len, buf, len);
720 WideCharToMultiByte(CP_OEMCP, 0, buf, len, d, len, NULL, NULL); 730 WideCharToMultiByte(CP_OEMCP, 0, buf, len, d, len, NULL, NULL);
@@ -744,6 +754,7 @@ static BOOL winansi_OemToCharBuff(LPCSTR s, LPSTR d, DWORD len)
744 if (!s || !d) 754 if (!s || !d)
745 return FALSE; 755 return FALSE;
746 756
757 terminal_mode(FALSE);
747 buf = xmalloc(len*sizeof(WCHAR)); 758 buf = xmalloc(len*sizeof(WCHAR));
748 MultiByteToWideChar(CP_OEMCP, 0, s, len, buf, len); 759 MultiByteToWideChar(CP_OEMCP, 0, s, len, buf, len);
749 WideCharToMultiByte(CP_ACP, 0, buf, len, d, len, NULL, NULL); 760 WideCharToMultiByte(CP_ACP, 0, buf, len, d, len, NULL, NULL);