diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2023-06-28 15:10:49 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-06-28 15:10:49 +0100 |
commit | ebe80f3e5c9b612f4d1b6e444c9badc10f9f2745 (patch) | |
tree | a3d46a237dfbd0c815469b52484431e35a9a237b /include | |
parent | 2984235570c2374adb9ee3234a61f193ee86d654 (diff) | |
download | busybox-w32-ebe80f3e5c9b612f4d1b6e444c9badc10f9f2745.tar.gz busybox-w32-ebe80f3e5c9b612f4d1b6e444c9badc10f9f2745.tar.bz2 busybox-w32-ebe80f3e5c9b612f4d1b6e444c9badc10f9f2745.zip |
win32: don't assume console CP equals OEM CP
Previously, console input was converted to the ANSI codepage using
OemToChar[Buff], and ANSI to console conversion used CharToOem[Buff].
However, while typically true by default, it's not guaranteed that
the console CP is the same as the OEM CP.
Now the code uses the console input/output CP as appropriate instead
of the OEM CP. It uses full wide-char conversion code, which was
previously limited to FEATURE_EURO, and now may be used also otherwise.
While at it, the code now bypasses the conversion altogether if the
src/dst CPs happen to be identical - which can definitely happen.
Other than saving some CPU cycles, this also happens to fix an issue
with the UTF8 manifest (in both input and output), because apparently
the Oem/Char conversion APIs fail to convert one char at a time (which
is not a complete UTF8 codepoint sequence) even if both the OEM and
the ANSI CPs are UTF8 (as is the case when using UTF8 manifest).
Conversion is also skipped:
- if the converted output would be longer than the input;
- if the input length is 1 and the input is multi-byte.
Diffstat (limited to 'include')
-rw-r--r-- | include/mingw.h | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/include/mingw.h b/include/mingw.h index 5d2fb39ee..a826d7eaa 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -150,7 +150,9 @@ IMPL(setlinebuf, void, ,FILE *fd UNUSED_PARAM) | |||
150 | * ANSI emulation wrappers | 150 | * ANSI emulation wrappers |
151 | */ | 151 | */ |
152 | 152 | ||
153 | BOOL winansi_OemToCharBuff(LPCSTR s, LPSTR d, DWORD len); | 153 | BOOL conToCharBuffA(LPSTR d, DWORD len); |
154 | BOOL conToCharA(LPSTR d); | ||
155 | |||
154 | void set_title(const char *str); | 156 | void set_title(const char *str); |
155 | void move_cursor_row(int n); | 157 | void move_cursor_row(int n); |
156 | void reset_screen(void); | 158 | void reset_screen(void); |
@@ -166,10 +168,7 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format | |||
166 | int winansi_write(int fd, const void *buf, size_t count); | 168 | int winansi_write(int fd, const void *buf, size_t count); |
167 | int winansi_read(int fd, void *buf, size_t count); | 169 | int winansi_read(int fd, void *buf, size_t count); |
168 | int winansi_getc(FILE *stream); | 170 | int winansi_getc(FILE *stream); |
169 | #if ENABLE_FEATURE_EURO | 171 | |
170 | # undef OemToCharBuff | ||
171 | # define OemToCharBuff winansi_OemToCharBuff | ||
172 | #endif | ||
173 | #define putchar winansi_putchar | 172 | #define putchar winansi_putchar |
174 | #define puts winansi_puts | 173 | #define puts winansi_puts |
175 | #define fwrite winansi_fwrite | 174 | #define fwrite winansi_fwrite |