aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2024-04-06 17:10:23 +0300
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2024-04-06 17:53:14 +0300
commit2b8bc1b4760d8ecb4fdcdd79923d29d0ab20b908 (patch)
treef8096aba428d22b4ab64b6e24b2c1be8cf154498 /win32
parent54dbf0fa510afcd3058a5da66e1c4a390c2ba89b (diff)
downloadbusybox-w32-2b8bc1b4760d8ecb4fdcdd79923d29d0ab20b908.tar.gz
busybox-w32-2b8bc1b4760d8ecb4fdcdd79923d29d0ab20b908.tar.bz2
busybox-w32-2b8bc1b4760d8ecb4fdcdd79923d29d0ab20b908.zip
win32: UTF8_OUTPUT: flush stream before conversion
writeCon_utf8 is unbuffered - it writes directly using WriteConsoleW, but some winansi libc IO wrappers, like fputs, use the libc API directly if the content doesn't need any special handling (e.g. all ASCII and no escape sequences), and so if the stream is buffered, and if only some parts of it go through writeCon_utf8, then we can get wrong output order due to some parts being buffered and some not. Case in point, the recent commit 54dbf0fa5 made the output of "time" buffered, and so if only parts of it go through writeCon_utf8, then we get bad output order. This did actually happen, because not all the winasi wrappers have this ASCII-only optimization (e.g. winansi_putchar), and "time" did end up with wrong output order. Even if all the winansi wrappers were ASCII-optimized, "time" could still have unicode output, e.g. with -f. Fix it by flushing the stream before converting using writeCon_utf8.
Diffstat (limited to 'win32')
-rw-r--r--win32/winansi.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index 66b040b31..dc98b9d2b 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -1590,8 +1590,10 @@ static int conv_fwriteCon(FILE *stream, char *buf, size_t siz)
1590{ 1590{
1591 if (conout_conv_enabled()) { 1591 if (conout_conv_enabled()) {
1592#if ENABLE_FEATURE_UTF8_OUTPUT 1592#if ENABLE_FEATURE_UTF8_OUTPUT
1593 if (GetConsoleOutputCP() != CP_UTF8) 1593 if (GetConsoleOutputCP() != CP_UTF8) {
1594 fflush(stream); // writeCon_utf8 is unbuffered
1594 return writeCon_utf8(fileno(stream), buf, siz) ? EOF : 0; 1595 return writeCon_utf8(fileno(stream), buf, siz) ? EOF : 0;
1596 }
1595#else 1597#else
1596 charToConBuffA(buf, siz); 1598 charToConBuffA(buf, siz);
1597#endif 1599#endif