API for __getmainargs() and __wgetmainargs() functions in msvcrt20.dll is
slightly different than in new msvcrt versions. In msvcrt20.dll these
functions return void and take new_mode parameter instead of the pointer to
the _startupinfo structure.

So for compatibility with mingw-w64 startup code, in msvcrt20 import
library rename exported __getmainargs/__wgetmainargs symbols to
__msvcrt20_getmainargs/__msvcrt20_wgetmainargs and provide mingw-w64
compatible wrappers named __getmainargs/__wgetmainargs around the
renamed symbols __msvcrt20_getmainargs/__msvcrt20_wgetmainargs.

See wine implementation for details:
https://gitlab.winehq.org/wine/wine/-/blob/wine-9.8/dlls/msvcrt20/msvcrt20.c
https://gitlab.winehq.org/wine/wine/-/commit/7f1e74a97ac92f84fcbc22f3bc986bd850af4448
---
 mingw-w64-crt/Makefile.am                 |  2 ++
 mingw-w64-crt/crt/msvcrt20_getmainargs.c  | 15 +++++++++++++++
 mingw-w64-crt/crt/msvcrt20_wgetmainargs.c | 15 +++++++++++++++
 mingw-w64-crt/lib32/msvcrt20.def.in       |  4 ++--
 4 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 mingw-w64-crt/crt/msvcrt20_getmainargs.c
 create mode 100644 mingw-w64-crt/crt/msvcrt20_wgetmainargs.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 788957dc81c1..258b8f358196 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -621,6 +621,8 @@ src_msvcrt10=\
   stdio/mingw_lock.c
 
 src_msvcrt20=\
+  crt/msvcrt20_getmainargs.c \
+  crt/msvcrt20_wgetmainargs.c \
   misc/___mb_cur_max_func.c \
   misc/__set_app_type.c \
   misc/dummy__setusermatherr.c \
diff --git a/mingw-w64-crt/crt/msvcrt20_getmainargs.c 
b/mingw-w64-crt/crt/msvcrt20_getmainargs.c
new file mode 100644
index 000000000000..3162a20ab359
--- /dev/null
+++ b/mingw-w64-crt/crt/msvcrt20_getmainargs.c
@@ -0,0 +1,15 @@
+/**
+ * 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 <internal.h>
+
+/* Define __getmainargs() function via msvcrt20.dll __getmainargs() function */
+_CRTIMP void __cdecl __msvcrt20_getmainargs(int *argc, char ***argv, char 
***envp, int expand_wildcards, int newmode);
+int __cdecl __getmainargs(int *argc, char ***argv, char ***envp, int 
expand_wildcards, _startupinfo *startup_info)
+{
+  __msvcrt20_getmainargs(argc, argv, envp, expand_wildcards, 
startup_info->newmode);
+  return 0;
+}
diff --git a/mingw-w64-crt/crt/msvcrt20_wgetmainargs.c 
b/mingw-w64-crt/crt/msvcrt20_wgetmainargs.c
new file mode 100644
index 000000000000..c8338bb0aca0
--- /dev/null
+++ b/mingw-w64-crt/crt/msvcrt20_wgetmainargs.c
@@ -0,0 +1,15 @@
+/**
+ * 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 <internal.h>
+
+/* Define __wgetmainargs() function via msvcrt20.dll __wgetmainargs() function 
*/
+_CRTIMP void __cdecl __msvcrt20_wgetmainargs(int *argc, wchar_t ***argv, 
wchar_t ***envp, int expand_wildcards, int newmode);
+int __cdecl __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***envp, int 
expand_wildcards, _startupinfo *startup_info)
+{
+  __msvcrt20_wgetmainargs(argc, argv, envp, expand_wildcards, 
startup_info->newmode);
+  return 0;
+}
diff --git a/mingw-w64-crt/lib32/msvcrt20.def.in 
b/mingw-w64-crt/lib32/msvcrt20.def.in
index 97c024874725..303514f1873b 100644
--- a/mingw-w64-crt/lib32/msvcrt20.def.in
+++ b/mingw-w64-crt/lib32/msvcrt20.def.in
@@ -898,7 +898,7 @@ __STRINGTOLD
 __dllonexit
 __doserrno
 __fpecode
-__getmainargs
+__msvcrt20_getmainargs == __getmainargs ; msvcrt20.dll's __getmainargs is 
incompatible with mingw-w64's __getmainargs, real __getmainargs provided by emu
 __isascii
 __iscsym
 __iscsymf
@@ -933,7 +933,7 @@ __pxcptinfoptrs
 __threadhandle
 __threadid
 __toascii
-__wgetmainargs
+__msvcrt20_wgetmainargs == __wgetmainargs ; msvcrt20.dll's __wgetmainargs is 
incompatible with mingw-w64's __wgetmainargs, real __wgetmainargs provided by 
emu
 _abnormal_termination
 _access
 _amsg_exit
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to