There is an entire collection of routines in mingw-w64-crt\secapi. These functions replicate the functionality of a number of secure versions of functions (_vcprintf_s, _wstrtime_s, etc). The idea was to support these functions on platforms which didn't have the necessary DLLs.

The purpose of the attached patches is to allow you to switch between using the internal versions, or the DLL versions. The patches select the DLL versions by default. In the (unlikely) event that you want the 'internal' versions, build your project with '-D_SECIMP='.

And incidentally it cleans up a number of "redeclared without dllimport attribute: previous dllimport ignored" warnings.

secimp1.patch - A number of the secapi\*.c files (actually all of them) duplicate the function prototypes of the functions they implement (and sometimes some of the functions they use as well) instead of simply including the appropriate header. This patch removes the duplicate definitions, and ensures that the correct headers are included.

secimp2.patch - Per Kai, these data imports are *always* resolved from DLLs. Having them 'follow' _CRTIMP is incorrect.

secimp3.patch - Replace all the _CRTIMP with _SECIMP on the secure functions to allow them to be controlled independently of the rest of the library functions. Note that while building mingw-w64 itself (aka defined(__LIBMSVCRT__)), _SECIMP must always be defined as blank to allow the internal versions to build without warnings.

dw

diff --git a/mingw-w64-crt/secapi/_access_s.c b/mingw-w64-crt/secapi/_access_s.c
index e5fea3b..9be582e 100644
--- a/mingw-w64-crt/secapi/_access_s.c
+++ b/mingw-w64-crt/secapi/_access_s.c
@@ -2,9 +2,8 @@
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <io.h>
 
-int __cdecl _access (const char *, int);
-errno_t __cdecl _access_s (const char *, int);
 static errno_t __cdecl _int_access_s (const char *, int);
 static errno_t __cdecl _stub (const char *, int);
 
diff --git a/mingw-w64-crt/secapi/_cgets_s.c b/mingw-w64-crt/secapi/_cgets_s.c
index a5023de..e70efe7 100644
--- a/mingw-w64-crt/secapi/_cgets_s.c
+++ b/mingw-w64-crt/secapi/_cgets_s.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/conio_s.h>
 
-char * __cdecl _cgets (char *);
-errno_t __cdecl _cgets_s (char *, size_t, size_t *);
 static errno_t __cdecl _int_cgets_s (char *, size_t, size_t *);
 static errno_t __cdecl _stub (char *, size_t, size_t *);
 
diff --git a/mingw-w64-crt/secapi/_cgetws_s.c b/mingw-w64-crt/secapi/_cgetws_s.c
index 9380ec3..dff4187 100644
--- a/mingw-w64-crt/secapi/_cgetws_s.c
+++ b/mingw-w64-crt/secapi/_cgetws_s.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/conio_s.h>
 
-wchar_t * __cdecl _cgetws (wchar_t *);
-errno_t __cdecl _cgetws_s (wchar_t *, size_t, size_t *);
 static errno_t __cdecl _int_cgetws_s (wchar_t *, size_t, size_t *);
 static errno_t __cdecl _stub (wchar_t *, size_t, size_t *);
 
diff --git a/mingw-w64-crt/secapi/_chsize_s.c b/mingw-w64-crt/secapi/_chsize_s.c
index 3993199..cd8d066 100644
--- a/mingw-w64-crt/secapi/_chsize_s.c
+++ b/mingw-w64-crt/secapi/_chsize_s.c
@@ -2,9 +2,8 @@
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <io.h>
 
-int __cdecl _chsize (int, long);
-errno_t __cdecl _chsize_s (int, long long);
 static errno_t __cdecl _int_chsize_s (int, long long);
 static errno_t __cdecl _stub (int, long long);
 
diff --git a/mingw-w64-crt/secapi/_cprintf_s.c b/mingw-w64-crt/secapi/_cprintf_s.c
index 8101bc1..36ea582 100644
--- a/mingw-w64-crt/secapi/_cprintf_s.c
+++ b/mingw-w64-crt/secapi/_cprintf_s.c
@@ -1,10 +1,9 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
-
-int __cdecl _cprintf_s (const char *,...);
-int __cdecl _vcprintf_s (const char *,va_list);
+#include <sec_api/conio_s.h>
 
 int __cdecl (*__MINGW_IMP_SYMBOL(_cprintf_s))(const char *,...) = 
  _cprintf_s;
diff --git a/mingw-w64-crt/secapi/_cprintf_s_l.c b/mingw-w64-crt/secapi/_cprintf_s_l.c
index 97fd4fb..316ca86 100644
--- a/mingw-w64-crt/secapi/_cprintf_s_l.c
+++ b/mingw-w64-crt/secapi/_cprintf_s_l.c
@@ -1,10 +1,9 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
-
-int __cdecl _cprintf_s_l (const char *, _locale_t, ...);
-int __cdecl _vcprintf_s_l(const char *,_locale_t,va_list);
+#include <sec_api/conio_s.h>
 
 int __cdecl (*__MINGW_IMP_SYMBOL(_cprintf_s_l))(const char *, _locale_t, ...) = 
  _cprintf_s_l;
diff --git a/mingw-w64-crt/secapi/_ctime32_s.c b/mingw-w64-crt/secapi/_ctime32_s.c
index 9c54914..c59ccfc 100644
--- a/mingw-w64-crt/secapi/_ctime32_s.c
+++ b/mingw-w64-crt/secapi/_ctime32_s.c
@@ -4,9 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _localtime32_s (struct tm *, const __time32_t *);
-errno_t __cdecl asctime_s (char *, size_t, const struct tm *);
-errno_t __cdecl _ctime32_s (char *, size_t, const __time32_t *);
 static errno_t __cdecl _int_ctime32_s (char *, size_t, const __time32_t *);
 static errno_t __cdecl _stub (char *, size_t, const __time32_t *);
 
diff --git a/mingw-w64-crt/secapi/_ctime64_s.c b/mingw-w64-crt/secapi/_ctime64_s.c
index d8722df..833d14a 100644
--- a/mingw-w64-crt/secapi/_ctime64_s.c
+++ b/mingw-w64-crt/secapi/_ctime64_s.c
@@ -4,9 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _localtime64_s (struct tm *, const __time64_t *);
-errno_t __cdecl asctime_s (char *, size_t, const struct tm *);
-errno_t __cdecl _ctime64_s (char *, size_t, const __time64_t *);
 static errno_t __cdecl _int_ctime64_s (char *, size_t, const __time64_t *);
 static errno_t __cdecl _stub (char *, size_t, const __time64_t *);
 
diff --git a/mingw-w64-crt/secapi/_cwprintf_s.c b/mingw-w64-crt/secapi/_cwprintf_s.c
index 3a4b8ae..b5ce0ab 100644
--- a/mingw-w64-crt/secapi/_cwprintf_s.c
+++ b/mingw-w64-crt/secapi/_cwprintf_s.c
@@ -1,10 +1,9 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
-
-int __cdecl _cwprintf_s (const wchar_t *,...);
-int __cdecl _vcwprintf_s (const wchar_t *,va_list);
+#include <sec_api/conio_s.h>
 
 int __cdecl (*__MINGW_IMP_SYMBOL(_cwprintf_s))(const wchar_t *,...) = 
  _cwprintf_s;
diff --git a/mingw-w64-crt/secapi/_cwprintf_s_l.c b/mingw-w64-crt/secapi/_cwprintf_s_l.c
index f3ae583..cadd55d 100644
--- a/mingw-w64-crt/secapi/_cwprintf_s_l.c
+++ b/mingw-w64-crt/secapi/_cwprintf_s_l.c
@@ -1,10 +1,9 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
-
-int __cdecl _cwprintf_s_l (const wchar_t *, _locale_t, ...);
-int __cdecl _vcwprintf_s_l(const wchar_t *,_locale_t,va_list);
+#include <sec_api/conio_s.h>
 
 int __cdecl (*__MINGW_IMP_SYMBOL(_cwprintf_s_l))(const wchar_t *, _locale_t, ...) = 
  _cwprintf_s_l;
diff --git a/mingw-w64-crt/secapi/_gmtime32_s.c b/mingw-w64-crt/secapi/_gmtime32_s.c
index 5919e42..7139c24 100644
--- a/mingw-w64-crt/secapi/_gmtime32_s.c
+++ b/mingw-w64-crt/secapi/_gmtime32_s.c
@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-/* struct tm * __cdecl _gmtime32 (const __time32_t *); */
-errno_t __cdecl _gmtime32_s (struct tm *, const __time32_t *);
 static errno_t __cdecl _int_gmtime32_s (struct tm *, const __time32_t *);
 static errno_t __cdecl _stub (struct tm *, const __time32_t *);
 
diff --git a/mingw-w64-crt/secapi/_gmtime64_s.c b/mingw-w64-crt/secapi/_gmtime64_s.c
index e9d7083..c4ca154 100644
--- a/mingw-w64-crt/secapi/_gmtime64_s.c
+++ b/mingw-w64-crt/secapi/_gmtime64_s.c
@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-/* struct tm * __cdecl _gmtime64 (const __time64_t *); */
-errno_t __cdecl _gmtime64_s (struct tm *, const __time64_t *);
 static errno_t __cdecl _int_gmtime64_s (struct tm *, const __time64_t *);
 static errno_t __cdecl _stub (struct tm *, const __time64_t *);
 
diff --git a/mingw-w64-crt/secapi/_localtime32_s.c b/mingw-w64-crt/secapi/_localtime32_s.c
index 323693b..c8a62f6 100644
--- a/mingw-w64-crt/secapi/_localtime32_s.c
+++ b/mingw-w64-crt/secapi/_localtime32_s.c
@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-/* struct tm * __cdecl _localtime32 (const __time32_t *); */
-errno_t __cdecl _localtime32_s (struct tm *, const __time32_t *);
 static errno_t __cdecl _int_localtime32_s (struct tm *, const __time32_t *);
 static errno_t __cdecl _stub (struct tm *, const __time32_t *);
 
diff --git a/mingw-w64-crt/secapi/_localtime64_s.c b/mingw-w64-crt/secapi/_localtime64_s.c
index 9552d71..bff0868 100644
--- a/mingw-w64-crt/secapi/_localtime64_s.c
+++ b/mingw-w64-crt/secapi/_localtime64_s.c
@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-/* struct tm * __cdecl _localtime64 (const __time64_t *); */
-errno_t __cdecl _localtime64_s (struct tm *, const __time64_t *);
 static errno_t __cdecl _int_localtime64_s (struct tm *, const __time64_t *);
 static errno_t __cdecl _stub (struct tm *, const __time64_t *);
 
diff --git a/mingw-w64-crt/secapi/_mktemp_s.c b/mingw-w64-crt/secapi/_mktemp_s.c
index d292e81..01484d9 100644
--- a/mingw-w64-crt/secapi/_mktemp_s.c
+++ b/mingw-w64-crt/secapi/_mktemp_s.c
@@ -2,10 +2,8 @@
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <io.h>
 
-size_t __cdecl strnlen (const char *, size_t);
-char * __cdecl _mktemp (char *);
-errno_t __cdecl _mktemp_s (char *, size_t);
 static errno_t __cdecl _int_mktemp_s (char *, size_t);
 static errno_t __cdecl _stub (char *, size_t);
 
diff --git a/mingw-w64-crt/secapi/_sopen_s.c b/mingw-w64-crt/secapi/_sopen_s.c
index 7d9645e..b4f8f6a 100644
--- a/mingw-w64-crt/secapi/_sopen_s.c
+++ b/mingw-w64-crt/secapi/_sopen_s.c
@@ -3,7 +3,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _sopen_s(int *, const char *, int, int, int);
 static errno_t __cdecl _int_sopen_s(int *, const char *, int, int, int);
 static errno_t __cdecl _stub(int *, const char *, int, int, int);
 
diff --git a/mingw-w64-crt/secapi/_strdate_s.c b/mingw-w64-crt/secapi/_strdate_s.c
index 5acce13..b62dec7 100644
--- a/mingw-w64-crt/secapi/_strdate_s.c
+++ b/mingw-w64-crt/secapi/_strdate_s.c
@@ -1,9 +1,9 @@
 #include <windows.h>
 #include <malloc.h>
+#include <time.h>
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _strdate_s (char *, size_t);
 static errno_t __cdecl _int_strdate_s (char *, size_t);
 static errno_t __cdecl _stub (char *, size_t);
 
diff --git a/mingw-w64-crt/secapi/_strtime_s.c b/mingw-w64-crt/secapi/_strtime_s.c
index 4e12e9b..b66e3f9 100644
--- a/mingw-w64-crt/secapi/_strtime_s.c
+++ b/mingw-w64-crt/secapi/_strtime_s.c
@@ -1,9 +1,9 @@
 #include <windows.h>
 #include <malloc.h>
+#include <time.h>
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _strtime_s (char *, size_t);
 static errno_t __cdecl _int_strtime_s (char *, size_t);
 static errno_t __cdecl _stub (char *, size_t);
 
diff --git a/mingw-w64-crt/secapi/_umask_s.c b/mingw-w64-crt/secapi/_umask_s.c
index 14f96a0..75e8ddb 100644
--- a/mingw-w64-crt/secapi/_umask_s.c
+++ b/mingw-w64-crt/secapi/_umask_s.c
@@ -2,9 +2,8 @@
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <io.h>
 
-int __cdecl _umask (int);
-errno_t __cdecl _umask_s (int, int *);
 static errno_t __cdecl _int_umask_s (int, int *);
 static errno_t __cdecl _stub (int, int *);
 
diff --git a/mingw-w64-crt/secapi/_vcprintf_s.c b/mingw-w64-crt/secapi/_vcprintf_s.c
index e6eab32..b512bb2 100644
--- a/mingw-w64-crt/secapi/_vcprintf_s.c
+++ b/mingw-w64-crt/secapi/_vcprintf_s.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/conio_s.h>
 
-int __cdecl _vcprintf (const char *, va_list);
-int __cdecl _vcprintf_s (const char *, va_list);
 static int __cdecl _int_vcprintf_s (const char *, va_list);
 static int __cdecl _stub (const char *, va_list);
 
diff --git a/mingw-w64-crt/secapi/_vcprintf_s_l.c b/mingw-w64-crt/secapi/_vcprintf_s_l.c
index 54e6a40..e4c86ce 100644
--- a/mingw-w64-crt/secapi/_vcprintf_s_l.c
+++ b/mingw-w64-crt/secapi/_vcprintf_s_l.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/conio_s.h>
 
-int __cdecl _vcprintf_l (const char *, _locale_t, va_list);
-int __cdecl _vcprintf_s_l (const char *, _locale_t, va_list);
 static int __cdecl _int_vcprintf_s_l (const char *, _locale_t, va_list);
 static int __cdecl _stub (const char *, _locale_t, va_list);
 
diff --git a/mingw-w64-crt/secapi/_vcwprintf_s.c b/mingw-w64-crt/secapi/_vcwprintf_s.c
index 6ac55a8..e6badb1 100644
--- a/mingw-w64-crt/secapi/_vcwprintf_s.c
+++ b/mingw-w64-crt/secapi/_vcwprintf_s.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/wchar_s.h>
 
-int __cdecl _vcwprintf (const wchar_t *, va_list);
-int __cdecl _vcwprintf_s (const wchar_t *, va_list);
 static int __cdecl _int_vcwprintf_s (const wchar_t *, va_list);
 static int __cdecl _stub (const wchar_t *, va_list);
 
diff --git a/mingw-w64-crt/secapi/_vcwprintf_s_l.c b/mingw-w64-crt/secapi/_vcwprintf_s_l.c
index 9e73161..2ce1def 100644
--- a/mingw-w64-crt/secapi/_vcwprintf_s_l.c
+++ b/mingw-w64-crt/secapi/_vcwprintf_s_l.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/wchar_s.h>
 
-int __cdecl _vcwprintf_l (const wchar_t *, _locale_t, va_list);
-int __cdecl _vcwprintf_s_l (const wchar_t *, _locale_t, va_list);
 static int __cdecl _int_vcwprintf_s_l (const wchar_t *, _locale_t, va_list);
 static int __cdecl _stub (const wchar_t *, _locale_t, va_list);
 
diff --git a/mingw-w64-crt/secapi/_vscprintf_p.c b/mingw-w64-crt/secapi/_vscprintf_p.c
index 7c4ea5b..c7ee3cc 100644
--- a/mingw-w64-crt/secapi/_vscprintf_p.c
+++ b/mingw-w64-crt/secapi/_vscprintf_p.c
@@ -1,9 +1,6 @@
-#define _vscprintf_p SAVE__vscprintf_p
 #define MINGW_HAS_SECURE_API 1
-#include <stdio.h>
-#undef _vscprintf_p
+#include <sec_api/stdio_s.h>
 
-int __cdecl _vscprintf_p(const char *format, va_list arglist);
 int __cdecl _vscprintf_p(const char *format, va_list arglist)
 {
     return _vscprintf_p_l(format, NULL, arglist);
diff --git a/mingw-w64-crt/secapi/_vscwprintf_p.c b/mingw-w64-crt/secapi/_vscwprintf_p.c
index e46cf30..498bc1c 100644
--- a/mingw-w64-crt/secapi/_vscwprintf_p.c
+++ b/mingw-w64-crt/secapi/_vscwprintf_p.c
@@ -1,9 +1,6 @@
-#define _vscwprintf_p SAVE__vscwprintf_p
 #define MINGW_HAS_SECURE_API 1
-#include <stdio.h>
-#undef _vscwprintf_p
+#include <sec_api/stdio_s.h>
 
-int __cdecl _vscwprintf_p(const wchar_t *format, va_list arglist);
 int __cdecl _vscwprintf_p(const wchar_t *format, va_list arglist)
 {
     return _vscwprintf_p_l(format, NULL, arglist);
diff --git a/mingw-w64-crt/secapi/_vswprintf_p.c b/mingw-w64-crt/secapi/_vswprintf_p.c
index c94dc7c..4823c81 100644
--- a/mingw-w64-crt/secapi/_vswprintf_p.c
+++ b/mingw-w64-crt/secapi/_vswprintf_p.c
@@ -1,9 +1,6 @@
-#define _vswprintf_p SAVE__vswprintf_p
 #define MINGW_HAS_SECURE_API 1
-#include <stdio.h>
-#undef _vswprintf_p
+#include <sec_api/stdio_s.h>
 
-int __cdecl _vswprintf_p(wchar_t *_DstBuf, size_t _MaxCount, const wchar_t *_Format, va_list _ArgList);
 int __cdecl _vswprintf_p(wchar_t *_DstBuf, size_t _MaxCount, const wchar_t *_Format, va_list _ArgList)
 {
     return _vswprintf_p_l(_DstBuf, _MaxCount, _Format, NULL, _ArgList);
diff --git a/mingw-w64-crt/secapi/_waccess_s.c b/mingw-w64-crt/secapi/_waccess_s.c
index e18971e..4ca83f4 100644
--- a/mingw-w64-crt/secapi/_waccess_s.c
+++ b/mingw-w64-crt/secapi/_waccess_s.c
@@ -1,10 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/wchar_s.h>
 
-int __cdecl _waccess (const wchar_t *e, int);
-errno_t __cdecl _waccess_s (const wchar_t *, int);
 static errno_t __cdecl _int_waccess_s (const wchar_t *, int);
 static errno_t __cdecl _stub (const wchar_t *, int);
 
diff --git a/mingw-w64-crt/secapi/_wasctime_s.c b/mingw-w64-crt/secapi/_wasctime_s.c
index 12adb5d..6b414ee 100644
--- a/mingw-w64-crt/secapi/_wasctime_s.c
+++ b/mingw-w64-crt/secapi/_wasctime_s.c
@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _wasctime_s (wchar_t *, size_t, const struct tm *);
-/* wchar_t * __cdecl _wasctime (const struct tm *); */
 static errno_t __cdecl _int_wasctime_s (wchar_t *, size_t, const struct tm *);
 static errno_t __cdecl _stub (wchar_t *, size_t, const struct tm *);
 
diff --git a/mingw-w64-crt/secapi/_wctime32_s.c b/mingw-w64-crt/secapi/_wctime32_s.c
index f86c210..27c414b 100644
--- a/mingw-w64-crt/secapi/_wctime32_s.c
+++ b/mingw-w64-crt/secapi/_wctime32_s.c
@@ -4,9 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _localtime32_s (struct tm *, const __time32_t *);
-errno_t __cdecl _wasctime_s (wchar_t *, size_t, const struct tm *);
-errno_t __cdecl _wctime32_s (wchar_t *, size_t, const __time32_t *);
 static errno_t __cdecl _int_wctime32_s (wchar_t *, size_t, const __time32_t *);
 static errno_t __cdecl _stub (wchar_t *, size_t, const __time32_t *);
 
diff --git a/mingw-w64-crt/secapi/_wctime64_s.c b/mingw-w64-crt/secapi/_wctime64_s.c
index 4d0bf8f..bce40fd 100644
--- a/mingw-w64-crt/secapi/_wctime64_s.c
+++ b/mingw-w64-crt/secapi/_wctime64_s.c
@@ -4,9 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _localtime64_s (struct tm *, const __time64_t *);
-errno_t __cdecl _wasctime_s (wchar_t *, size_t, const struct tm *);
-errno_t __cdecl _wctime64_s (wchar_t *, size_t, const __time64_t *);
 static errno_t __cdecl _int_wctime64_s (wchar_t *, size_t, const __time64_t *);
 static errno_t __cdecl _stub (wchar_t *, size_t, const __time64_t *);
 
diff --git a/mingw-w64-crt/secapi/_wmktemp_s.c b/mingw-w64-crt/secapi/_wmktemp_s.c
index 75b3d5f..3cbf0c7 100644
--- a/mingw-w64-crt/secapi/_wmktemp_s.c
+++ b/mingw-w64-crt/secapi/_wmktemp_s.c
@@ -1,11 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/wchar_s.h>
 
-size_t __cdecl wcsnlen (const wchar_t *, size_t);
-char * __cdecl _wmktemp (wchar_t *);
-errno_t __cdecl _wmktemp_s (wchar_t *, size_t);
 static errno_t __cdecl _int_wmktemp_s (wchar_t *, size_t);
 static errno_t __cdecl _stub (wchar_t *, size_t);
 
diff --git a/mingw-w64-crt/secapi/_wstrdate_s.c b/mingw-w64-crt/secapi/_wstrdate_s.c
index fc557ad..e8ec1d4 100644
--- a/mingw-w64-crt/secapi/_wstrdate_s.c
+++ b/mingw-w64-crt/secapi/_wstrdate_s.c
@@ -1,9 +1,9 @@
 #include <windows.h>
 #include <malloc.h>
+#include <time.h>
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _wstrdate_s (wchar_t *, size_t);
 static errno_t __cdecl _int_wstrdate_s (wchar_t *, size_t);
 static errno_t __cdecl _stub (wchar_t *, size_t);
 
diff --git a/mingw-w64-crt/secapi/_wstrtime_s.c b/mingw-w64-crt/secapi/_wstrtime_s.c
index f328643..ffb8a3e 100644
--- a/mingw-w64-crt/secapi/_wstrtime_s.c
+++ b/mingw-w64-crt/secapi/_wstrtime_s.c
@@ -1,9 +1,9 @@
 #include <windows.h>
 #include <malloc.h>
+#include <time.h>
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl _wstrtime_s (wchar_t *, size_t);
 static errno_t __cdecl _int_wstrtime_s (wchar_t *, size_t);
 static errno_t __cdecl _stub (wchar_t *, size_t);
 
diff --git a/mingw-w64-crt/secapi/asctime_s.c b/mingw-w64-crt/secapi/asctime_s.c
index 1ce49d3..aeb16e3 100644
--- a/mingw-w64-crt/secapi/asctime_s.c
+++ b/mingw-w64-crt/secapi/asctime_s.c
@@ -4,8 +4,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl asctime_s (char *, size_t, const struct tm *);
-/* char * __cdecl asctime (const struct tm *); */
 static errno_t __cdecl _int_asctime_s (char *, size_t, const struct tm *);
 static errno_t __cdecl _stub (char *, size_t, const struct tm *);
 
diff --git a/mingw-w64-crt/secapi/memcpy_s.c b/mingw-w64-crt/secapi/memcpy_s.c
index 2e66136..013eff0 100644
--- a/mingw-w64-crt/secapi/memcpy_s.c
+++ b/mingw-w64-crt/secapi/memcpy_s.c
@@ -3,7 +3,6 @@
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl memcpy_s (void *, size_t, const void *, size_t);
 static errno_t __cdecl _int_memcpy_s (void *, size_t, const void *, size_t);
 static errno_t __cdecl _stub (void *, size_t, const void *, size_t);
 
diff --git a/mingw-w64-crt/secapi/memmove_s.c b/mingw-w64-crt/secapi/memmove_s.c
index a7b8501..170bdf3 100644
--- a/mingw-w64-crt/secapi/memmove_s.c
+++ b/mingw-w64-crt/secapi/memmove_s.c
@@ -1,9 +1,9 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
 
-errno_t __cdecl memmove_s (void *, size_t, const void *, size_t);
 static errno_t __cdecl _int_memmove_s (void *, size_t, const void *, size_t);
 static errno_t __cdecl _stub (void *, size_t, const void *, size_t);
 
diff --git a/mingw-w64-crt/secapi/sprintf_s.c b/mingw-w64-crt/secapi/sprintf_s.c
index 8c60797..3b92d07 100644
--- a/mingw-w64-crt/secapi/sprintf_s.c
+++ b/mingw-w64-crt/secapi/sprintf_s.c
@@ -1,10 +1,9 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
-
-int __cdecl sprintf_s (char *, size_t, const char *, ...);
-int __cdecl vsprintf_s (char *, size_t, const char *, va_list);
+#include <sec_api/stdio_s.h>
 
 int __cdecl (*__MINGW_IMP_SYMBOL(sprintf_s))(char *, size_t, const char *,...) = sprintf_s;
 
diff --git a/mingw-w64-crt/secapi/strerror_s.c b/mingw-w64-crt/secapi/strerror_s.c
index 714ad9b..148236d 100644
--- a/mingw-w64-crt/secapi/strerror_s.c
+++ b/mingw-w64-crt/secapi/strerror_s.c
@@ -1,11 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/stdio_s.h>
 
-char * __cdecl strerror (int);
-errno_t __cdecl strerror_s (char *, size_t, int);
-int __cdecl sprintf_s (char *, size_t, const char *, ...);
 static errno_t __cdecl _int_strerror_s (char *, size_t, int);
 static errno_t __cdecl _stub (char *, size_t, int);
 
diff --git a/mingw-w64-crt/secapi/vsprintf_s.c b/mingw-w64-crt/secapi/vsprintf_s.c
index 47486e3..96a7680 100644
--- a/mingw-w64-crt/secapi/vsprintf_s.c
+++ b/mingw-w64-crt/secapi/vsprintf_s.c
@@ -1,10 +1,11 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
 #include <stdio.h>
+#include <sec_api/stdio_s.h>
 
-int __cdecl vsprintf_s (char *, size_t, const char *, va_list);
 static int __cdecl _int_vsprintf_s (char *, size_t, const char *, va_list);
 static int __cdecl _stub (char *, size_t, const char *, va_list);
 
diff --git a/mingw-w64-crt/secapi/wmemcpy_s.c b/mingw-w64-crt/secapi/wmemcpy_s.c
index 16e2178..bb59bdc 100644
--- a/mingw-w64-crt/secapi/wmemcpy_s.c
+++ b/mingw-w64-crt/secapi/wmemcpy_s.c
@@ -1,9 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/wchar_s.h>
 
-errno_t __cdecl wmemcpy_s (wchar_t *, size_t, const wchar_t *, size_t);
 static errno_t __cdecl _int_wmemcpy_s (wchar_t *, size_t, const wchar_t *, size_t);
 static errno_t __cdecl _stub (wchar_t *, size_t, const wchar_t *, size_t);
 
diff --git a/mingw-w64-crt/secapi/wmemmove_s.c b/mingw-w64-crt/secapi/wmemmove_s.c
index c15f50b..788fa7e 100644
--- a/mingw-w64-crt/secapi/wmemmove_s.c
+++ b/mingw-w64-crt/secapi/wmemmove_s.c
@@ -1,9 +1,10 @@
+#define MINGW_HAS_SECURE_API 1
 #include <windows.h>
 #include <malloc.h>
 #include <errno.h>
 #include <msvcrt.h>
+#include <sec_api/wchar_s.h>
 
-errno_t __cdecl wmemmove_s (wchar_t *, size_t, const wchar_t *, size_t);
 static errno_t __cdecl _int_wmemmove_s (wchar_t *, size_t, const wchar_t*, size_t);
 static errno_t __cdecl _stub (wchar_t *, size_t, const wchar_t *, size_t);
 
diff --git a/mingw-w64-crt/include/internal.h b/mingw-w64-crt/include/internal.h
index 03fe1c1..e2f2d59 100644
--- a/mingw-w64-crt/include/internal.h
+++ b/mingw-w64-crt/include/internal.h
@@ -28,7 +28,7 @@ extern "C" {
 #if defined (SPECIAL_CRTEXE) && (defined (_DLL) || defined (__GNUC__))
   extern int _commode;
 #else
-  _CRTIMP extern int _commode;
+  __declspec(dllimport) extern int _commode;
 #endif
 
 #define __IOINFO_TM_ANSI 0
diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h
index dfc5ae4..85bc5f2 100644
--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -152,8 +152,8 @@ extern "C" {
   extern char *_sys_errlist[];
   extern int _sys_nerr;
 #else
-  extern _CRTIMP char *_sys_errlist[1];
-  extern _CRTIMP int _sys_nerr;
+  extern __declspec(dllimport) char *_sys_errlist[1];
+  extern __declspec(dllimport) int _sys_nerr;
 #endif
 #if (defined(_X86_) && !defined(__x86_64))
   _CRTIMP int *__cdecl __p___argc(void);
diff --git a/mingw-w64-headers/crt/xmath.h b/mingw-w64-headers/crt/xmath.h
index 6b47c19..1e8d513 100644
--- a/mingw-w64-headers/crt/xmath.h
+++ b/mingw-w64-headers/crt/xmath.h
@@ -86,23 +86,23 @@ _CRTIMP short __cdecl _Dscale(double *,long);
 _CRTIMP short __cdecl _Dunscale(short *,double *);
 _CRTIMP double __cdecl _Poly(double,const double *,int);
 
-extern _CRTIMP _Dconst _Eps,_Rteps;
-extern _CRTIMP double _Xbig;
+extern __declspec(dllimport) _Dconst _Eps,_Rteps;
+extern __declspec(dllimport) double _Xbig;
 
 _CRTIMP short __cdecl _FDnorm(unsigned short *);
 _CRTIMP short __cdecl _FDscale(float *,long);
 _CRTIMP short __cdecl _FDunscale(short *,float *);
 
-extern _CRTIMP _Dconst _FEps,_FRteps;
-extern _CRTIMP float _FXbig;
+extern __declspec(dllimport) _Dconst _FEps,_FRteps;
+extern __declspec(dllimport) float _FXbig;
 
 _CRTIMP short __cdecl _LDnorm(unsigned short *);
 _CRTIMP short __cdecl _LDscale(long double *,long);
 _CRTIMP short __cdecl _LDunscale(short *,long double *);
 _CRTIMP long double __cdecl _LPoly(long double,const long double *,int);
 
-extern _CRTIMP _Dconst _LEps,_LRteps;
-extern _CRTIMP long double _LXbig;
+extern __declspec(dllimport) _Dconst _LEps,_LRteps;
+extern __declspec(dllimport) long double _LXbig;
 _END_C_LIB_DECL
 _C_STD_END
 #endif
diff --git a/mingw-w64-headers/crt/float.h b/mingw-w64-headers/crt/float.h
index 5874f4e..de23bb9 100644
--- a/mingw-w64-headers/crt/float.h
+++ b/mingw-w64-headers/crt/float.h
@@ -11,6 +11,15 @@
  *
  */
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #if (defined (__GNUC__) && defined (__GNUC_MINOR__)) \
     || (defined(__clang__) && defined(__clang_major__))
 #if (__GNUC__ < 4  || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) \
@@ -242,7 +251,7 @@ extern "C" {
  * i.e. change the bits in unMask to have the values they have in unNew,
  * leaving other bits unchanged. */
 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, unsigned int unMask) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-_CRTIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask);
+_SECIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask);
 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int unNew, unsigned int unMask);
 
 
diff --git a/mingw-w64-headers/crt/io.h b/mingw-w64-headers/crt/io.h
index c61e94a..92ad977 100644
--- a/mingw-w64-headers/crt/io.h
+++ b/mingw-w64-headers/crt/io.h
@@ -9,6 +9,15 @@
 #include <crtdefs.h>
 #include <string.h>
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #pragma pack(push,_CRT_PACKING)
 
 #ifdef __cplusplus
@@ -176,10 +185,10 @@ _CRTIMP char* __cdecl _getcwd (char*, int);
 #define	R_OK	4	/* Check for read permission */
 
   _CRTIMP int __cdecl _access(const char *_Filename,int _AccessMode);
-  _CRTIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode);
+  _SECIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode);
   _CRTIMP int __cdecl _chmod(const char *_Filename,int _Mode);
   _CRTIMP int __cdecl _chsize(int _FileHandle,long _Size) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _chsize_s (int _FileHandle,__int64 _Size);
+  _SECIMP errno_t __cdecl _chsize_s (int _FileHandle,__int64 _Size);
   _CRTIMP int __cdecl _close(int _FileHandle);
   _CRTIMP int __cdecl _commit(int _FileHandle);
   _CRTIMP int __cdecl _creat(const char *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
@@ -195,7 +204,7 @@ _CRTIMP char* __cdecl _getcwd (char*, int);
   _CRTIMP long __cdecl _lseek(int _FileHandle,long _Offset,int _Origin);
   _off64_t lseek64(int fd,_off64_t offset, int whence);
   _CRTIMP char *__cdecl _mktemp(char *_TemplateName) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _mktemp_s (char *_TemplateName,size_t _Size);
+  _SECIMP errno_t __cdecl _mktemp_s (char *_TemplateName,size_t _Size);
   _CRTIMP int __cdecl _pipe(int *_PtHandles,unsigned int _PipeSize,int _TextMode);
   _CRTIMP int __cdecl _read(int _FileHandle,void *_DstBuf,unsigned int _MaxCharCount);
 
@@ -212,7 +221,7 @@ _CRTIMP char* __cdecl _getcwd (char*, int);
   _CRTIMP int __cdecl _setmode(int _FileHandle,int _Mode);
   _CRTIMP long __cdecl _tell(int _FileHandle);
   _CRTIMP int __cdecl _umask(int _Mode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _umask_s (int _NewMode,int *_OldMode);
+  _SECIMP errno_t __cdecl _umask_s (int _NewMode,int *_OldMode);
   _CRTIMP int __cdecl _write(int _FileHandle,const void *_Buf,unsigned int _MaxCharCount);
 
   __MINGW_EXTENSION _CRTIMP __int64 __cdecl _filelengthi64(int _FileHandle);
@@ -275,7 +284,7 @@ _CRTIMP char* __cdecl _getcwd (char*, int);
 #endif /* _UWIN */
 #endif /* Not NO_OLDNAMES */
 
-  _CRTIMP errno_t __cdecl _sopen_s(int *_FileHandle,const char *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode);
+  _SECIMP errno_t __cdecl _sopen_s(int *_FileHandle,const char *_Filename,int _OpenFlag,int _ShareFlag,int _PermissionMode);
 
   _CRTIMP int __cdecl _open(const char *_Filename,int _OpenFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
   _CRTIMP int __cdecl _sopen(const char *_Filename,int _OpenFlag,int _ShareFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
@@ -283,7 +292,7 @@ _CRTIMP char* __cdecl _getcwd (char*, int);
 #ifndef _WIO_DEFINED
 #define _WIO_DEFINED
   _CRTIMP int __cdecl _waccess(const wchar_t *_Filename,int _AccessMode);
-  _CRTIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode);
+  _SECIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode);
   _CRTIMP int __cdecl _wchmod(const wchar_t *_Filename,int _Mode);
   _CRTIMP int __cdecl _wcreat(const wchar_t *_Filename,int _PermissionMode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
   _CRTIMP intptr_t __cdecl _wfindfirst32(const wchar_t *_Filename,struct _wfinddata32_t *_FindData);
@@ -291,7 +300,7 @@ _CRTIMP char* __cdecl _getcwd (char*, int);
   _CRTIMP int __cdecl _wunlink(const wchar_t *_Filename);
   _CRTIMP int __cdecl _wrename(const wchar_t *_OldFilename,const wchar_t *_NewFilename);
   _CRTIMP wchar_t *__cdecl _wmktemp(wchar_t *_TemplateName) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName, size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName, size_t _SizeInWords);
 
   _CRTIMP intptr_t __cdecl _wfindfirst32i64(const wchar_t *_Filename,struct _wfinddata32i64_t *_FindData);
   intptr_t __cdecl _wfindfirst64i32(const wchar_t *_Filename,struct _wfinddata64i32_t *_FindData);
diff --git a/mingw-w64-headers/crt/memory.h b/mingw-w64-headers/crt/memory.h
index b4937e9..333771d 100644
--- a/mingw-w64-headers/crt/memory.h
+++ b/mingw-w64-headers/crt/memory.h
@@ -8,6 +8,15 @@
 
 #include <crtdefs.h>
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -26,7 +35,7 @@ extern "C" {
   _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale);
   int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size);
   void * __cdecl memcpy(void * __restrict__ _Dst,const void * __restrict__ _Src,size_t _Size) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl memcpy_s (void *_dest,size_t _numberOfElements,const void *_src,size_t _count);
+  _SECIMP errno_t __cdecl memcpy_s (void *_dest,size_t _numberOfElements,const void *_src,size_t _count);
   void * __cdecl mempcpy (void *_Dst, const void *_Src, size_t _Size);
   void * __cdecl memset(void *_Dst,int _Val,size_t _Size);
 
diff --git a/mingw-w64-headers/crt/sec_api/conio_s.h b/mingw-w64-headers/crt/sec_api/conio_s.h
index 95703eb..2fe2a50 100644
--- a/mingw-w64-headers/crt/sec_api/conio_s.h
+++ b/mingw-w64-headers/crt/sec_api/conio_s.h
@@ -11,31 +11,40 @@
 
 #if defined(MINGW_HAS_SECURE_API)
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-  _CRTIMP errno_t __cdecl _cgets_s (char *_Buffer,size_t _Size,size_t *_SizeRead);
+  _SECIMP errno_t __cdecl _cgets_s (char *_Buffer,size_t _Size,size_t *_SizeRead);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _cgets_s, char, _Buffer, size_t*, _SizeRead)
 
-  _CRTIMP int __cdecl _cprintf_s (const char *_Format,...);
+  _SECIMP int __cdecl _cprintf_s (const char *_Format,...);
   _CRTIMP int __cdecl _cscanf_s(const char *_Format,...);
   _CRTIMP int __cdecl _cscanf_s_l(const char *_Format,_locale_t _Locale,...);
-  _CRTIMP int __cdecl _vcprintf_s (const char *_Format,va_list _ArgList);
-  _CRTIMP int __cdecl _cprintf_s_l (const char *_Format,_locale_t _Locale,...);
-  _CRTIMP int __cdecl _vcprintf_s_l (const char *_Format,_locale_t _Locale,va_list _ArgList);
+  _SECIMP int __cdecl _vcprintf_s (const char *_Format,va_list _ArgList);
+  _SECIMP int __cdecl _cprintf_s_l (const char *_Format,_locale_t _Locale,...);
+  _SECIMP int __cdecl _vcprintf_s_l (const char *_Format,_locale_t _Locale,va_list _ArgList);
 
 #ifndef _WCONIO_S_DEFINED
 #define _WCONIO_S_DEFINED
-  _CRTIMP errno_t __cdecl _cgetws_s (wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead);
+  _SECIMP errno_t __cdecl _cgetws_s (wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _cgetws_s, wchar_t, _Buffer, size_t*, _SizeRead)
 
-  _CRTIMP int __cdecl _cwprintf_s (const wchar_t *_Format,...);
+  _SECIMP int __cdecl _cwprintf_s (const wchar_t *_Format,...);
   _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...);
   _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...);
-  _CRTIMP int __cdecl _vcwprintf_s (const wchar_t *_Format,va_list _ArgList);
-  _CRTIMP int __cdecl _cwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,...);
-  _CRTIMP int __cdecl _vcwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
+  _SECIMP int __cdecl _vcwprintf_s (const wchar_t *_Format,va_list _ArgList);
+  _SECIMP int __cdecl _cwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,...);
+  _SECIMP int __cdecl _vcwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
 #endif
 
 #ifdef __cplusplus
diff --git a/mingw-w64-headers/crt/sec_api/stdio_s.h b/mingw-w64-headers/crt/sec_api/stdio_s.h
index aa51af7..092f337 100644
--- a/mingw-w64-headers/crt/sec_api/stdio_s.h
+++ b/mingw-w64-headers/crt/sec_api/stdio_s.h
@@ -10,6 +10,15 @@
 
 #if defined(MINGW_HAS_SECURE_API)
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -42,10 +51,10 @@ extern "C" {
   _CRTIMP int __cdecl _vsnprintf_s(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,va_list _ArgList);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_3(int,_vsnprintf_s,char,_DstBuf,size_t,_MaxCount,const char*,_Format,va_list,_ArgList)
 
-  int __cdecl vsprintf_s(char *_DstBuf,size_t _Size,const char *_Format,va_list _ArgList);
+  _SECIMP int __cdecl vsprintf_s(char *_DstBuf,size_t _Size,const char *_Format,va_list _ArgList);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(int, vsprintf_s, char, _DstBuf, const char*, _Format, va_list, _ArgList)
 
-  int __cdecl sprintf_s(char *_DstBuf,size_t _DstSize,const char *_Format,...);
+  _SECIMP int __cdecl sprintf_s(char *_DstBuf,size_t _DstSize,const char *_Format,...);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1_ARGLIST(int,sprintf_s,vsprintf_s,char,_DstBuf,const char*,_Format)
 
   _CRTIMP int __cdecl _snprintf_s(char *_DstBuf,size_t _DstSize,size_t _MaxCount,const char *_Format,...);
@@ -58,7 +67,7 @@ extern "C" {
   _CRTIMP int __cdecl _vprintf_p(const char *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _vsprintf_p(char *_Dst,size_t _MaxCount,const char *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _scprintf_p(const char *_Format,...);
-  _CRTIMP int __cdecl _vscprintf_p(const char *_Format,va_list _ArgList);
+  _SECIMP int __cdecl _vscprintf_p(const char *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _printf_l(const char *_Format,_locale_t _Locale,...);
   _CRTIMP int __cdecl _printf_p_l(const char *_Format,_locale_t _Locale,...);
   _CRTIMP int __cdecl _vprintf_l(const char *_Format,_locale_t _Locale,va_list _ArgList);
@@ -145,9 +154,9 @@ extern "C" {
   _CRTIMP int __cdecl _vfwprintf_p(FILE *_File,const wchar_t *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _vwprintf_p(const wchar_t *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _swprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,...);
-  _CRTIMP int __cdecl _vswprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,va_list _ArgList);
+  _SECIMP int __cdecl _vswprintf_p(wchar_t *_DstBuf,size_t _MaxCount,const wchar_t *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _scwprintf_p(const wchar_t *_Format,...);
-  _CRTIMP int __cdecl _vscwprintf_p(const wchar_t *_Format,va_list _ArgList);
+  _SECIMP int __cdecl _vscwprintf_p(const wchar_t *_Format,va_list _ArgList);
   _CRTIMP int __cdecl _wprintf_l(const wchar_t *_Format,_locale_t _Locale,...);
   _CRTIMP int __cdecl _wprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...);
   _CRTIMP int __cdecl _vwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
diff --git a/mingw-w64-headers/crt/sec_api/string_s.h b/mingw-w64-headers/crt/sec_api/string_s.h
index 114cfd7..42000fb 100644
--- a/mingw-w64-headers/crt/sec_api/string_s.h
+++ b/mingw-w64-headers/crt/sec_api/string_s.h
@@ -10,13 +10,22 @@
 
 #if defined(MINGW_HAS_SECURE_API)
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
   _CRTIMP errno_t __cdecl _strset_s(char *_Dst,size_t _DstSize,int _Value);
   _CRTIMP errno_t __cdecl _strerror_s(char *_Buf,size_t _SizeInBytes,const char *_ErrMsg);
-  _CRTIMP errno_t __cdecl strerror_s(char *_Buf,size_t _SizeInBytes,int _ErrNum);
+  _SECIMP errno_t __cdecl strerror_s(char *_Buf,size_t _SizeInBytes,int _ErrNum);
   _CRTIMP errno_t __cdecl _strlwr_s(char *_Str,size_t _Size);
   _CRTIMP errno_t __cdecl _strlwr_s_l(char *_Str,size_t _Size,_locale_t _Locale);
   _CRTIMP errno_t __cdecl _strnset_s(char *_Str,size_t _Size,int _Val,size_t _MaxCount);
@@ -36,7 +45,7 @@ extern "C" {
   _CRTIMP errno_t __cdecl strcat_s(char *_Dst, rsize_t _SizeInBytes, const char * _Src);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcat_s, char, _Dest, const char *, _Source)
 
-  _CRTIMP errno_t __cdecl memmove_s(void *_dest,size_t _numberOfElements,const void *_src,size_t _count);
+  _SECIMP errno_t __cdecl memmove_s(void *_dest,size_t _numberOfElements,const void *_src,size_t _count);
 #ifndef _WSTRING_S_DEFINED
 #define _WSTRING_S_DEFINED
   _CRTIMP wchar_t *__cdecl wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context);
diff --git a/mingw-w64-headers/crt/sec_api/wchar_s.h b/mingw-w64-headers/crt/sec_api/wchar_s.h
index fe09632..c88be6e 100644
--- a/mingw-w64-headers/crt/sec_api/wchar_s.h
+++ b/mingw-w64-headers/crt/sec_api/wchar_s.h
@@ -10,25 +10,34 @@
 
 #if defined(MINGW_HAS_SECURE_API)
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #ifndef _WIO_S_DEFINED
 #define _WIO_S_DEFINED
-  _CRTIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode);
-  errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode);
+  _SECIMP errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName,size_t _SizeInWords);
 #endif
 
 #ifndef _WCONIO_S_DEFINED
 #define _WCONIO_S_DEFINED
-  errno_t __cdecl _cgetws_s (wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead);
-  int __cdecl _cwprintf_s (const wchar_t *_Format,...);
+  _SECIMP errno_t __cdecl _cgetws_s (wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead);
+  _SECIMP int __cdecl _cwprintf_s (const wchar_t *_Format,...);
   _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...);
   _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...);
-  int __cdecl _vcwprintf_s (const wchar_t *_Format,va_list _ArgList);
-  int __cdecl _cwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,...);
-  int __cdecl _vcwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
+  _SECIMP int __cdecl _vcwprintf_s (const wchar_t *_Format,va_list _ArgList);
+  _SECIMP int __cdecl _cwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,...);
+  _SECIMP int __cdecl _vcwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
 #endif
 
 #ifndef _WSTDIO_S_DEFINED
@@ -138,11 +147,11 @@ extern "C" {
 
 #ifndef _WTIME_S_DEFINED
 #define _WTIME_S_DEFINED
-  errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm);
-  errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time);
-  errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords);
-  errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords);
-  errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time);
+  _SECIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm);
+  _SECIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time);
+  _SECIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time);
 
 #if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL)
 #define _INC_WTIME_S_INL
@@ -162,8 +171,9 @@ __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,cons
   _CRTIMP errno_t __cdecl wcsrtombs_s(size_t *_Retval,char *_Dst,size_t _SizeInBytes,const wchar_t **_Src,size_t _Size,mbstate_t *_State);
   __DEFINE_CPP_OVERLOAD_SECURE_FUNC_1_3(errno_t,wcsrtombs_s,size_t,_Retval,char,_Dst,const wchar_t**,_Src,size_t,_Size,mbstate_t,_State)
 
-  _CRTIMP errno_t __cdecl wmemcpy_s (wchar_t *_dest,size_t _numberOfElements,const wchar_t *_src,size_t _count);
-  _CRTIMP errno_t __cdecl wmemmove_s(wchar_t *_dest,size_t _numberOfElements,const wchar_t *_src,size_t _count);
+  _SECIMP errno_t __cdecl wmemcpy_s (wchar_t *_dest,size_t _numberOfElements,const wchar_t *_src,size_t _count);
+  _SECIMP errno_t __cdecl wmemmove_s(wchar_t *_dest,size_t _numberOfElements,const wchar_t *_src,size_t _count);
+
 
 #ifdef __cplusplus
 }
diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h
index dfc5ae4..a1ac5d0 100644
--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -13,6 +13,15 @@
 #define __USE_MINGW_STRTOX 1
 #endif
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #pragma pack(push,_CRT_PACKING)
 
 #ifdef __cplusplus
@@ -388,7 +397,7 @@ extern "C" {
   #endif
 #endif
 #ifdef _CRT_RAND_S
-  _CRTIMP errno_t __cdecl rand_s(unsigned int *randomValue);
+  _SECIMP errno_t __cdecl rand_s(unsigned int *randomValue);
 #endif
 
 #if defined(__USE_MINGW_STRTOX)
diff --git a/mingw-w64-headers/crt/string.h b/mingw-w64-headers/crt/string.h
index 84c8d71..c8c8018 100644
--- a/mingw-w64-headers/crt/string.h
+++ b/mingw-w64-headers/crt/string.h
@@ -8,6 +8,15 @@
 
 #include <crtdefs.h>
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -39,7 +48,7 @@ extern "C" {
   _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale);
   int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size);
   void * __cdecl memcpy(void * __restrict__ _Dst,const void * __restrict__ _Src,size_t _Size) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl memcpy_s (void *_dest,size_t _numberOfElements,const void *_src,size_t _count);
+  _SECIMP errno_t __cdecl memcpy_s (void *_dest,size_t _numberOfElements,const void *_src,size_t _count);
   void * __cdecl mempcpy (void *_Dst, const void *_Src, size_t _Size);
   void * __cdecl memset(void *_Dst,int _Val,size_t _Size);
 #ifndef	NO_OLDNAMES
diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h
index 64d709f..7f5bbb7 100644
--- a/mingw-w64-headers/crt/time.h
+++ b/mingw-w64-headers/crt/time.h
@@ -12,6 +12,15 @@
 #error Only Win32 target is supported!
 #endif
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #pragma pack(push,_CRT_PACKING)
 
 #ifdef __cplusplus
@@ -110,21 +119,21 @@ extern "C" {
   _CRTIMP errno_t __cdecl _get_timezone(long *_Timezone);
   _CRTIMP errno_t __cdecl _get_tzname(size_t *_ReturnValue,char *_Buffer,size_t _SizeInBytes,int _Index);
   char *__cdecl asctime(const struct tm *_Tm) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl asctime_s (char *_Buf,size_t _SizeInWords,const struct tm *_Tm);
+  _SECIMP errno_t __cdecl asctime_s (char *_Buf,size_t _SizeInWords,const struct tm *_Tm);
   char *__cdecl _ctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _ctime32_s (char *_Buf,size_t _SizeInBytes,const __time32_t *_Time);
+  _SECIMP errno_t __cdecl _ctime32_s (char *_Buf,size_t _SizeInBytes,const __time32_t *_Time);
   clock_t __cdecl clock(void);
   double __cdecl _difftime32(__time32_t _Time1,__time32_t _Time2);
   struct tm *__cdecl _gmtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _gmtime32_s (struct tm *_Tm,const __time32_t *_Time);
+  _SECIMP errno_t __cdecl _gmtime32_s (struct tm *_Tm,const __time32_t *_Time);
   struct tm *__cdecl _localtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _localtime32_s (struct tm *_Tm,const __time32_t *_Time);
+  _SECIMP errno_t __cdecl _localtime32_s (struct tm *_Tm,const __time32_t *_Time);
   size_t __cdecl strftime(char * __restrict__ _Buf,size_t _SizeInBytes,const char * __restrict__ _Format,const struct tm * __restrict__ _Tm);
   _CRTIMP size_t __cdecl _strftime_l(char * __restrict__ _Buf,size_t _Max_size,const char * __restrict__ _Format,const struct tm * __restrict__ _Tm,_locale_t _Locale);
   _CRTIMP char *__cdecl _strdate(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _strdate_s (char *_Buf,size_t _SizeInBytes);
+  _SECIMP errno_t __cdecl _strdate_s (char *_Buf,size_t _SizeInBytes);
   _CRTIMP char *__cdecl _strtime(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _strtime_s (char *_Buf ,size_t _SizeInBytes);
+  _SECIMP errno_t __cdecl _strtime_s (char *_Buf ,size_t _SizeInBytes);
   __time32_t __cdecl _time32(__time32_t *_Time);
   __time32_t __cdecl _mktime32(struct tm *_Tm);
   __time32_t __cdecl _mkgmtime32(struct tm *_Tm);
@@ -138,11 +147,11 @@ extern "C" {
 
   double __cdecl _difftime64(__time64_t _Time1,__time64_t _Time2);
   _CRTIMP char *__cdecl _ctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  errno_t __cdecl _ctime64_s (char *_Buf,size_t _SizeInBytes,const __time64_t *_Time);
+  _SECIMP errno_t __cdecl _ctime64_s (char *_Buf,size_t _SizeInBytes,const __time64_t *_Time);
   _CRTIMP struct tm *__cdecl _gmtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _gmtime64_s (struct tm *_Tm,const __time64_t *_Time);
+  _SECIMP errno_t __cdecl _gmtime64_s (struct tm *_Tm,const __time64_t *_Time);
   _CRTIMP struct tm *__cdecl _localtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _localtime64_s (struct tm *_Tm,const __time64_t *_Time);
+  _SECIMP errno_t __cdecl _localtime64_s (struct tm *_Tm,const __time64_t *_Time);
   _CRTIMP __time64_t __cdecl _mktime64(struct tm *_Tm);
   _CRTIMP __time64_t __cdecl _mkgmtime64(struct tm *_Tm);
   _CRTIMP __time64_t __cdecl _time64(__time64_t *_Time);
@@ -151,17 +160,17 @@ extern "C" {
 
 #ifndef _WTIME_DEFINED
   _CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm);
-  _CRTIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm);
+  _SECIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm);
   wchar_t *__cdecl _wctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time);
+  _SECIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time);
   size_t __cdecl wcsftime(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm);
   _CRTIMP size_t __cdecl _wcsftime_l(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm,_locale_t _Locale);
   _CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords);
   _CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords);
   _CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time);
+  _SECIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time);
 
 #if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL)
 #define _INC_WTIME_INL
diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h
index 9265d0b..aa3fb9e 100644
--- a/mingw-w64-headers/crt/wchar.h
+++ b/mingw-w64-headers/crt/wchar.h
@@ -13,6 +13,15 @@
 #define __USE_MINGW_STRTOX 1
 #endif
 
+#if defined(__LIBMSVCRT__)
+/* When building mingw-w64, this should be blank.  */
+#define _SECIMP
+#else
+#ifndef _SECIMP
+#define _SECIMP __declspec(dllimport)
+#endif /* _SECIMP */
+#endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
+
 #pragma pack(push,_CRT_PACKING)
 
 #ifdef __cplusplus
@@ -688,9 +697,9 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, __builti
   _CRTIMP int __cdecl _vfwprintf_p(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,va_list _ArgList);
   _CRTIMP int __cdecl _vwprintf_p(const wchar_t * __restrict__ _Format,va_list _ArgList);
   _CRTIMP int __cdecl _swprintf_p(wchar_t * __restrict__ _DstBuf,size_t _MaxCount,const wchar_t * __restrict__ _Format,...);
-  _CRTIMP int __cdecl _vswprintf_p(wchar_t * __restrict__ _DstBuf,size_t _MaxCount,const wchar_t * __restrict__ _Format,va_list _ArgList);
+  _SECIMP int __cdecl _vswprintf_p(wchar_t * __restrict__ _DstBuf,size_t _MaxCount,const wchar_t * __restrict__ _Format,va_list _ArgList);
   _CRTIMP int __cdecl _scwprintf_p(const wchar_t * __restrict__ _Format,...);
-  _CRTIMP int __cdecl _vscwprintf_p(const wchar_t * __restrict__ _Format,va_list _ArgList);
+  _SECIMP int __cdecl _vscwprintf_p(const wchar_t * __restrict__ _Format,va_list _ArgList);
   _CRTIMP int __cdecl _wprintf_l(const wchar_t * __restrict__ _Format,_locale_t _Locale,...);
   _CRTIMP int __cdecl _wprintf_p_l(const wchar_t * __restrict__ _Format,_locale_t _Locale,...);
   _CRTIMP int __cdecl _vwprintf_l(const wchar_t * __restrict__ _Format,_locale_t _Locale,va_list _ArgList);
@@ -913,17 +922,17 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, __builti
 #define _WTIME_DEFINED
 
   _CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm);
-  _CRTIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm);
+  _SECIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm);
   wchar_t *__cdecl _wctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time);
+  _SECIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time);
   size_t __cdecl wcsftime(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm);
   _CRTIMP size_t __cdecl _wcsftime_l(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm,_locale_t _Locale);
   _CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords);
   _CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords);
+  _SECIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords);
   _CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
-  _CRTIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time);
+  _SECIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time);
 
 #if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL)
 #define _INC_WTIME_INL
------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to