It requires adding compatibility code for x86_64 msvcrt version. I don't
have arm setup to test, but I assume it's present there.

Signed-off-by: Jacek Caban <[email protected]>
---
 mingw-w64-crt/Makefile.am           |  1 +
 mingw-w64-crt/crt/crtexe.c          |  2 +-
 mingw-w64-crt/crt/ucrtbase_compat.c |  2 --
 mingw-w64-crt/misc/__p__fmode.c     | 17 +++++++++++++++++
 mingw-w64-headers/crt/stdlib.h      | 20 +++++++-------------
 5 files changed, 26 insertions(+), 16 deletions(-)
 create mode 100644 mingw-w64-crt/misc/__p__fmode.c


diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 6812a5eb..8f03db88 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -228,6 +228,7 @@ src_msvcrt64=\
   $(src_msvcrt) \
   misc/__p___argv.c \
   misc/__p__acmdln.c \
+  misc/__p__fmode.c \
   misc/__p__wcmdln.c
 
 src_msvcrtarm32=\
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index b4b694d2..3ee1f988 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -139,7 +139,7 @@ pre_c_init (void)
     __set_app_type (_CONSOLE_APP);
   __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
 
-  * __MINGW_IMP_SYMBOL(_fmode) = _fmode;
+  * __p__fmode() = _fmode;
   * __MINGW_IMP_SYMBOL(_commode) = _commode;
 
 #ifdef WPRFLAG
diff --git a/mingw-w64-crt/crt/ucrtbase_compat.c b/mingw-w64-crt/crt/ucrtbase_compat.c
index e6956c8c..6b061227 100644
--- a/mingw-w64-crt/crt/ucrtbase_compat.c
+++ b/mingw-w64-crt/crt/ucrtbase_compat.c
@@ -120,10 +120,8 @@ unsigned int __cdecl _get_output_format(void)
 
 static char ** local__initenv;
 static wchar_t ** local__winitenv;
-static int local_fmode;
 char *** __MINGW_IMP_SYMBOL(__initenv) = &local__initenv;
 wchar_t *** __MINGW_IMP_SYMBOL(__winitenv) = &local__winitenv;
-int * __MINGW_IMP_SYMBOL(_fmode) = &local_fmode;
 
 
 // The parts below are mostly ugly workarounds, necessary to appease code
diff --git a/mingw-w64-crt/misc/__p__fmode.c b/mingw-w64-crt/misc/__p__fmode.c
new file mode 100644
index 00000000..f788a6fc
--- /dev/null
+++ b/mingw-w64-crt/misc/__p__fmode.c
@@ -0,0 +1,17 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <_mingw.h>
+
+extern int * __MINGW_IMP_SYMBOL(_fmode);
+
+int *__cdecl __p__fmode(void);
+int *__cdecl __p__fmode(void)
+{
+    return __MINGW_IMP_SYMBOL(_fmode);
+}
+
+typeof(__p__fmode) *__MINGW_IMP_SYMBOL(__p__fmode) = __p__fmode;
diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h
index bf2c0897..4d9c1d96 100644
--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -174,9 +174,10 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
 #endif /* __MSVCRT_VERSION__ < 0x1400 */
 #endif
 
-  // We have a fallback definition of __p___argv for msvcrt versions that
-  // lack it.
+  /* We have a fallback definition of __p___argv and __p__fmode for
+     msvcrt versions that lack it. */
   _CRTIMP char ***__cdecl __p___argv(void);
+  _CRTIMP int *__cdecl __p__fmode(void);
 #if (defined(_X86_) && !defined(__x86_64)) || (__MSVCRT_VERSION__ >= 0x1400)
   _CRTIMP int *__cdecl __p___argc(void);
   _CRTIMP wchar_t ***__cdecl __p___wargv(void);
@@ -184,7 +185,6 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
   _CRTIMP wchar_t ***__cdecl __p__wenviron(void);
   _CRTIMP char **__cdecl __p__pgmptr(void);
   _CRTIMP wchar_t **__cdecl __p__wpgmptr(void);
-  _CRTIMP int *__cdecl __p__fmode(void);
 #endif
 
   errno_t __cdecl _get_pgmptr(char **_Value);
@@ -192,6 +192,10 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
   _CRTIMP errno_t __cdecl _set_fmode(int _Mode);
   _CRTIMP errno_t __cdecl _get_fmode(int *_PMode);
 
+#ifndef _fmode
+#define _fmode (* __p__fmode())
+#endif
+
 #ifdef _MSVCRT_
 
 #ifndef __argc
@@ -220,9 +224,6 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
 #ifndef _wpgmptr
   extern wchar_t *_wpgmptr;
 #endif
-#ifndef _fmode
-  extern int _fmode;
-#endif
 
 #ifndef _osplatform
   extern unsigned int _osplatform;
@@ -273,9 +274,6 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
 #ifndef _wpgmptr
 #define _wpgmptr (* __p__wpgmptr())
 #endif
-#ifndef _fmode
-#define _fmode (* __p__fmode())
-#endif
 
 #else /* __MSVCRT_VERSION__ >= 0x1400 */
 
@@ -313,10 +311,6 @@ _CRTIMP int __cdecl ___mb_cur_max_func(void);
   extern wchar_t ** __MINGW_IMP_SYMBOL(_wpgmptr);
 #define _wpgmptr (* __MINGW_IMP_SYMBOL(_wpgmptr))
 #endif
-#ifndef _fmode
-  extern int * __MINGW_IMP_SYMBOL(_fmode);
-#define _fmode	(* __MINGW_IMP_SYMBOL(_fmode))
-#endif
 
 #ifndef _osplatform
   extern unsigned int * __MINGW_IMP_SYMBOL(_osplatform);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to