aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2023-06-28 15:10:49 +0100
committerRon Yorston <rmy@pobox.com>2023-06-28 15:10:49 +0100
commitebe80f3e5c9b612f4d1b6e444c9badc10f9f2745 (patch)
treea3d46a237dfbd0c815469b52484431e35a9a237b /include
parent2984235570c2374adb9ee3234a61f193ee86d654 (diff)
downloadbusybox-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.h9
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
153BOOL winansi_OemToCharBuff(LPCSTR s, LPSTR d, DWORD len); 153BOOL conToCharBuffA(LPSTR d, DWORD len);
154BOOL conToCharA(LPSTR d);
155
154void set_title(const char *str); 156void set_title(const char *str);
155void move_cursor_row(int n); 157void move_cursor_row(int n);
156void reset_screen(void); 158void reset_screen(void);
@@ -166,10 +168,7 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format
166int winansi_write(int fd, const void *buf, size_t count); 168int winansi_write(int fd, const void *buf, size_t count);
167int winansi_read(int fd, void *buf, size_t count); 169int winansi_read(int fd, void *buf, size_t count);
168int winansi_getc(FILE *stream); 170int 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