Hi,

I have problem with "Hello World" example with _O_U8TEXT mode. Sample code:
    _setmode(_fileno(stderr), _O_U8TEXT);
    fputws(L"Hello ", stderr);
    fwprintf(stderr, L"%ls\n", L"World");

If I compile this code with __USE_MINGW_ANSI_STDIO, it prints nothing, if without __USE_MINGW_ANSI_STDIO, it prints only "World" (on Windows 7).

If I link to msvcr110.dll instead of msvcrt.dll, it prints "Hello World" in both cases.

If I apply attached hello.patch to mingw-w64 (to patch only libmsvcrt.a) it prints "Hello World" in both cases.

It seems that 'fputwc' and 'fputws' from msvcrt.dll doesn't work with _O_U8TEXT mode (for console streams), but 'fwprintf' works OK.

Does anyone have a better idea of the patch of this error?

#define __USE_MINGW_ANSI_STDIO 1

#include <stdio.h>
#include <io.h>
#include <fcntl.h>

int main()
{
    _setmode(_fileno(stderr), _O_U8TEXT);
    fputws(L"Hello ", stderr);
    fwprintf(stderr, L"%ls\n", L"World");
}
diff --git a/mingw-w64-crt/lib32/msvcrt.def.in 
b/mingw-w64-crt/lib32/msvcrt.def.in
index 71bdf56..24c21cd 100644
--- a/mingw-w64-crt/lib32/msvcrt.def.in
+++ b/mingw-w64-crt/lib32/msvcrt.def.in
@@ -572,8 +572,8 @@ fopen
 fprintf
 fputc
 fputs
-fputwc
-fputws
+;fputwc
+;fputws
 fread
 free
 freopen
@@ -585,6 +585,7 @@ fseek
 fsetpos
 ftell
 fwprintf
+__ms_fwprintf == fwprintf
 fwrite
 fwscanf
 getc
diff --git a/mingw-w64-crt/lib64/msvcrt.def.in 
b/mingw-w64-crt/lib64/msvcrt.def.in
index 946c200..e229c86 100644
--- a/mingw-w64-crt/lib64/msvcrt.def.in
+++ b/mingw-w64-crt/lib64/msvcrt.def.in
@@ -1070,8 +1070,8 @@ fprintf
 fprintf_s
 fputc
 fputs
-fputwc
-fputws
+;fputwc
+;fputws
 fread
 free
 freopen
@@ -1084,6 +1084,7 @@ fseek
 fsetpos
 ftell
 fwprintf
+__ms_fwprintf == fwprintf
 fwprintf_s
 fwrite
 fwscanf
diff --git a/mingw-w64-crt/stdio/mingw_lock.c b/mingw-w64-crt/stdio/mingw_lock.c
index e62fe03..ff15d30 100644
--- a/mingw-w64-crt/stdio/mingw_lock.c
+++ b/mingw-w64-crt/stdio/mingw_lock.c
@@ -95,3 +95,18 @@ void __cdecl _unlock_file( FILE *pf )
          */
         LeaveCriticalSection( &(((_FILEX *)pf)->lock) );
 }
+
+
+int __cdecl __ms_fwprintf(FILE *, const wchar_t *, ...);
+
+wint_t __cdecl fputwc(wchar_t _Ch, FILE *_File)
+{
+    if (__ms_fwprintf(_File, L"%c", _Ch) > 0)
+        return _Ch;
+    return WEOF;
+}
+
+int __cdecl fputws(const wchar_t *_Str, FILE *_File)
+{
+    return __ms_fwprintf(_File, L"%s", _Str);
+}
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to