On Fri, Jun 12, 2020 at 2:06 PM Piotr Caban piotr.caban@gmail.com wrote:
Hi,
On 6/11/20 1:10 AM, Pauli wrote:
When I tested the buffered output I had mixed results. Characters rendedred correctly in wineconsole cmd. Too bad output was still grabage because same output was written multiple times.
I've sent a patch for fflush function that clears the buffer even if error occurs (https://source.winehq.org/patches/data/186903). It should fix some of the cases when output is written multiple times.
Your patch fixes the repeated output issue from my application too. Thanks.
After reading wine debug log I figured that issue was around WriteFile call from MSVCRT__write. stdout has WX_TEXT set leading to path which assumes WriteFile sets BytesWritten to actual number of bytes. But kernel32.WriteFile does mb to wc conversion (correctly) but it then writes number of wide characters written.
In the tests you have attached the fflush failure is caused by incorrect value set by ConsoleWriteA function. On Wine ConsoleWriteA(sout, test, sizeof(test) - 1, &written, NULL) sets written to 1, on Windows to 3. Please create a bug report about that (bugs.winehq.org).
I reported the bug: https://bugs.winehq.org/show_bug.cgi?id=49378
I looked a bit more into kernel32 code. It seems like an easy fix if I could call something like mbrlen or mbrtowc. The Wine code indicates kernel32.dll doesn't have access to any similar code page aware function. As i don't know coding rules well enough I'm not going to attempt to fix such a complex issue.
Thanks, Piotr