From 80a52b6aa4c75feac878356617af7bad5620454b Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Fri, 23 Nov 2012 11:18:28 +0000 Subject: [PATCH] Fix Unicode output on the console, broken in 33866, fixed in 34042, broken again in 38185, fixed again in 51058 and finally broken yet another time since 54651... I think this history deserves champagne and forceful warning comments, which have been added. Simple solution: Don't blindly sync Wine code! #resolve #CORE-6495 svn path=/trunk/; revision=57747 --- reactos/lib/sdk/crt/stdio/file.c | 43 ++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/reactos/lib/sdk/crt/stdio/file.c b/reactos/lib/sdk/crt/stdio/file.c index 7c063754606..e1e045f94fb 100644 --- a/reactos/lib/sdk/crt/stdio/file.c +++ b/reactos/lib/sdk/crt/stdio/file.c @@ -7,6 +7,14 @@ * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org) */ +/********************************************* + * This file contains ReactOS changes!! + * Don't blindly sync it with Wine code! + * + * If you break Unicode output on the console again, please update this counter: + * int hours_wasted_on_this = 42; + *********************************************/ + /* * msvcrt.dll file functions * @@ -2505,13 +2513,38 @@ size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE* file) /********************************************************************* * fputwc (MSVCRT.@) + * FORKED for ReactOS, don't sync with Wine! + * References: + * - http://jira.reactos.org/browse/CORE-6495 + * - http://bugs.winehq.org/show_bug.cgi?id=8598 */ -wint_t CDECL fputwc(wint_t wc, FILE* file) +wint_t CDECL fputwc(wchar_t c, FILE* stream) { - wchar_t mwc=wc; - if (fwrite( &mwc, sizeof(mwc), 1, file) != 1) - return WEOF; - return wc; + /* If this is a real file stream (and not some temporary one for + sprintf-like functions), check whether it is opened in text mode. + In this case, we have to perform an implicit conversion to ANSI. */ + if (!(stream->_flag & _IOSTRG) && get_ioinfo(stream->_file)->wxflag & WX_TEXT) + { + /* Convert to multibyte in text mode */ + char mbc[MB_LEN_MAX]; + int mb_return; + + mb_return = wctomb(mbc, c); + + if(mb_return == -1) + return WEOF; + + /* Output all characters */ + if (fwrite(mbc, mb_return, 1, stream) != 1) + return WEOF; + } + else + { + if (fwrite(&c, sizeof(c), 1, stream) != 1) + return WEOF; + } + + return c; } /*********************************************************************