crt: Move implementation of __initenv and __winitenv to common file misc/__initenv.c
crtdll.dll and ucrt needs same implementation of __initenv and __winitenv
symbols. Deduplicate code and move it into a new misc/__initenv.c file.
Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 305d1b9..af2169c 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -238,6 +238,7 @@
src_ucrtbase=\
crt/ucrtbase_compat.c \
math/_huge.c \
+ misc/__initenv.c \
stdio/ucrt_fprintf.c \
stdio/ucrt_fscanf.c \
stdio/ucrt_fwprintf.c \
@@ -418,6 +419,7 @@
src_crtdll=\
crt/crtdll_compat.c \
misc/___mb_cur_max_func.c \
+ misc/__initenv.c \
misc/__p___argv.c \
misc/__p__acmdln.c \
misc/__p__commode.c \
diff --git a/mingw-w64-crt/crt/crtdll_compat.c b/mingw-w64-crt/crt/crtdll_compat.c
index 9bb48bd..3568665 100644
--- a/mingw-w64-crt/crt/crtdll_compat.c
+++ b/mingw-w64-crt/crt/crtdll_compat.c
@@ -7,12 +7,6 @@
#include <internal.h>
#include <math.h>
-/* Define __initenv and __winitenv as crtdll.dll does not provide them */
-static char ** local__initenv;
-static wchar_t ** local__winitenv;
-char *** __MINGW_IMP_SYMBOL(__initenv) = &local__initenv;
-wchar_t *** __MINGW_IMP_SYMBOL(__winitenv) = &local__winitenv;
-
/* Define dummy __setusermatherr() function as crtdll.dll does not provide it */
#undef __setusermatherr
void __setusermatherr(__UNUSED_PARAM(int (__cdecl *f)(struct _exception *))) { }
diff --git a/mingw-w64-crt/crt/ucrtbase_compat.c b/mingw-w64-crt/crt/ucrtbase_compat.c
index d01293a..02910ff 100644
--- a/mingw-w64-crt/crt/ucrtbase_compat.c
+++ b/mingw-w64-crt/crt/ucrtbase_compat.c
@@ -111,11 +111,6 @@
return 0;
}
-static char ** local__initenv;
-static wchar_t ** local__winitenv;
-char *** __MINGW_IMP_SYMBOL(__initenv) = &local__initenv;
-wchar_t *** __MINGW_IMP_SYMBOL(__winitenv) = &local__winitenv;
-
// These are required to provide the unrepfixed data symbols "timezone"
// and "tzname"; we can't remap "timezone" via a define due to clashes
diff --git a/mingw-w64-crt/misc/__initenv.c b/mingw-w64-crt/misc/__initenv.c
new file mode 100644
index 0000000..31fd875
--- /dev/null
+++ b/mingw-w64-crt/misc/__initenv.c
@@ -0,0 +1,12 @@
+/**
+ * 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>
+
+static char ** local__initenv;
+static wchar_t ** local__winitenv;
+char *** __MINGW_IMP_SYMBOL(__initenv) = &local__initenv;
+wchar_t *** __MINGW_IMP_SYMBOL(__winitenv) = &local__winitenv;