Author: cfinck
Date: Fri Nov 23 11:18:28 2012
New Revision: 57747
URL:
http://svn.reactos.org/svn/reactos?rev=57747&view=rev
Log:
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
Modified:
trunk/reactos/lib/sdk/crt/stdio/file.c
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?r…
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Fri Nov 23 11:18:28 2012
@@ -6,6 +6,14 @@
* PROGRAMMERS: Wine team
* Ported to ReactOS by Aleksey Bragin (aleksey(a)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 @@
/*********************************************************************
* fputwc (MSVCRT.@)
- */
-wint_t CDECL fputwc(wint_t wc, FILE* file)
-{
- wchar_t mwc=wc;
- if (fwrite( &mwc, sizeof(mwc), 1, file) != 1)
- return WEOF;
- return wc;
+ * 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(wchar_t c, FILE* stream)
+{
+ /* 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;
}
/*********************************************************************