mingw: building and linking msvcrt-os.lib

This commit is contained in:
Andrew Kelley 2019-07-10 16:17:09 -04:00
parent ea90a3a9a1
commit 67f3bc9101
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
63 changed files with 4282 additions and 3 deletions

View File

@ -7613,15 +7613,72 @@ set(ZIG_LIBC_FILES
"mingw/crt/xncommod.c"
"mingw/crt/xthdloc.c"
"mingw/crt/xtxtmode.c"
"mingw/def-include/.func.def.in.swp"
"mingw/def-include/.msvcrt-common.def.in.swp"
"mingw/def-include/func.def.in"
"mingw/def-include/msvcrt-common.def.in"
"mingw/include/config.h"
"mingw/include/internal.h"
"mingw/include/msvcrt.h"
"mingw/include/oscalls.h"
"mingw/include/sect_attribs.h"
"mingw/lib-common/kernel32.def.in"
"mingw/lib-common/msvcrt.def.in"
"mingw/misc/__p___argv.c"
"mingw/misc/__p__acmdln.c"
"mingw/misc/__p__fmode.c"
"mingw/misc/__p__wcmdln.c"
"mingw/misc/_configthreadlocale.c"
"mingw/misc/_get_current_locale.c"
"mingw/misc/invalid_parameter_handler.c"
"mingw/misc/lc_locale_func.c"
"mingw/misc/onexit_table.c"
"mingw/misc/output_format.c"
"mingw/misc/purecall.c"
"mingw/misc/register_tls_atexit.c"
"mingw/secapi/_access_s.c"
"mingw/secapi/_cgets_s.c"
"mingw/secapi/_cgetws_s.c"
"mingw/secapi/_chsize_s.c"
"mingw/secapi/_controlfp_s.c"
"mingw/secapi/_cprintf_s.c"
"mingw/secapi/_cprintf_s_l.c"
"mingw/secapi/_ctime32_s.c"
"mingw/secapi/_ctime64_s.c"
"mingw/secapi/_cwprintf_s.c"
"mingw/secapi/_cwprintf_s_l.c"
"mingw/secapi/_gmtime32_s.c"
"mingw/secapi/_gmtime64_s.c"
"mingw/secapi/_localtime32_s.c"
"mingw/secapi/_localtime64_s.c"
"mingw/secapi/_mktemp_s.c"
"mingw/secapi/_sopen_s.c"
"mingw/secapi/_strdate_s.c"
"mingw/secapi/_strtime_s.c"
"mingw/secapi/_umask_s.c"
"mingw/secapi/_vcprintf_s.c"
"mingw/secapi/_vcprintf_s_l.c"
"mingw/secapi/_vcwprintf_s.c"
"mingw/secapi/_vcwprintf_s_l.c"
"mingw/secapi/_vscprintf_p.c"
"mingw/secapi/_vscwprintf_p.c"
"mingw/secapi/_vswprintf_p.c"
"mingw/secapi/_waccess_s.c"
"mingw/secapi/_wasctime_s.c"
"mingw/secapi/_wctime32_s.c"
"mingw/secapi/_wctime64_s.c"
"mingw/secapi/_wmktemp_s.c"
"mingw/secapi/_wstrdate_s.c"
"mingw/secapi/_wstrtime_s.c"
"mingw/secapi/asctime_s.c"
"mingw/secapi/memcpy_s.c"
"mingw/secapi/memmove_s.c"
"mingw/secapi/rand_s.c"
"mingw/secapi/sprintf_s.c"
"mingw/secapi/strerror_s.c"
"mingw/secapi/vsprintf_s.c"
"mingw/secapi/wmemcpy_s.c"
"mingw/secapi/wmemmove_s.c"
"mingw/stdio/acrt_iob_func.c"
"mingw/stdio/mingw_lock.c"
"musl/arch/aarch64/atomic_arch.h"
"musl/arch/aarch64/bits/alltypes.h.in"
"musl/arch/aarch64/bits/endian.h"

View File

@ -0,0 +1,10 @@
#include <winbase.h>
#ifndef __LIBMSVCRT__
#error "This file should only be used in libmsvcrt.a"
#endif
static inline HANDLE __mingw_get_msvcrt_handle(void)
{
return GetModuleHandleW(L"msvcrt.dll");
}

File diff suppressed because it is too large Load Diff

View File

@ -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 <stdlib.h>
char ***__cdecl __p___argv(void)
{
return __MINGW_IMP_SYMBOL(__argv);
}
typedef char ***__cdecl (*_f__p___argv)(void);
_f__p___argv __MINGW_IMP_SYMBOL(__p___argv) = __p___argv;

View File

@ -0,0 +1,18 @@
/**
* 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 char ** __MINGW_IMP_SYMBOL(_acmdln);
char **__cdecl __p__acmdln(void);
char **__cdecl __p__acmdln(void)
{
return __MINGW_IMP_SYMBOL(_acmdln);
}
typedef char **__cdecl (*_f__p__acmdln)(void);
_f__p__acmdln __MINGW_IMP_SYMBOL(__p__acmdln) = __p__acmdln;

View File

@ -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;

View File

@ -0,0 +1,18 @@
/**
* 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 <wchar.h>
extern wchar_t ** __MINGW_IMP_SYMBOL(_wcmdln);
wchar_t **__cdecl __p__wcmdln(void);
wchar_t **__cdecl __p__wcmdln(void)
{
return __MINGW_IMP_SYMBOL(_wcmdln);
}
typedef wchar_t **__cdecl (*_f__p__wcmdln)(void);
_f__p__wcmdln __MINGW_IMP_SYMBOL(__p__wcmdln) = __p__wcmdln;

View File

@ -0,0 +1,16 @@
/**
* 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 <locale.h>
int __cdecl _configthreadlocale(int flag)
{
/* _ENABLE_PER_THREAD_LOCALE can't work on msvcrt.dll. */
return flag == _ENABLE_PER_THREAD_LOCALE ? -1 : _DISABLE_PER_THREAD_LOCALE;
}
void *__MINGW_IMP_SYMBOL(_configthreadlocale) = _configthreadlocale;

View File

@ -0,0 +1,26 @@
#include <windows.h>
#include <locale.h>
#include <msvcrt.h>
static _locale_t __cdecl init_func(void);
_locale_t (__cdecl *__MINGW_IMP_SYMBOL(_get_current_locale))(void) = init_func;
static _locale_t __cdecl null_func(void)
{
return NULL;
}
static _locale_t __cdecl init_func(void)
{
HMODULE msvcrt = __mingw_get_msvcrt_handle();
_locale_t (__cdecl *func)(void) = NULL;
if (msvcrt) {
func = (void*)GetProcAddress(msvcrt, "_get_current_locale");
}
if (!func)
func = null_func;
return (__MINGW_IMP_SYMBOL(_get_current_locale) = func)();
}

View File

@ -0,0 +1,23 @@
#define _CRTIMP
#include <windows.h>
typedef void (__cdecl *_invalid_parameter_handler)(const wchar_t *,const wchar_t *,const wchar_t *,unsigned int,uintptr_t);
static _invalid_parameter_handler handler;
static _invalid_parameter_handler __cdecl mingw_set_invalid_parameter_handler(_invalid_parameter_handler new_handler)
{
return InterlockedExchangePointer((void**)&handler, new_handler);
}
_invalid_parameter_handler (__cdecl *__MINGW_IMP_SYMBOL(_set_invalid_parameter_handler))(_invalid_parameter_handler) =
mingw_set_invalid_parameter_handler;
static _invalid_parameter_handler __cdecl mingw_get_invalid_parameter_handler(void)
{
return handler;
}
_invalid_parameter_handler (__cdecl *__MINGW_IMP_SYMBOL(_get_invalid_parameter_handler))(void) = mingw_get_invalid_parameter_handler;
_invalid_parameter_handler __cdecl _get_invalid_parameter_handler(void) __attribute__ ((alias ("mingw_get_invalid_parameter_handler")));
_invalid_parameter_handler __cdecl _set_invalid_parameter_handler(_invalid_parameter_handler new_handler) __attribute__ ((alias ("mingw_set_invalid_parameter_handler")));

View File

@ -0,0 +1,50 @@
#define __lc_codepage __dummy_lc_codepage
#define ___lc_codepage_func __dummy____lc_codepage_func
#include <windows.h>
#include <locale.h>
#include <msvcrt.h>
#undef __lc_codepage
#undef ___lc_codepage_func
#include "mb_wc_common.h"
static unsigned int *msvcrt__lc_codepage;
static unsigned int __cdecl msvcrt___lc_codepage_func(void)
{
return *msvcrt__lc_codepage;
}
static unsigned int __cdecl setlocale_codepage_hack(void)
{
/* locale :: "lang[_country[.code_page]]" | ".code_page" */
const char *cp_str = strchr (setlocale(LC_CTYPE, NULL), '.');
return cp_str ? atoi(cp_str + 1) : 0;
}
static unsigned int __cdecl init_codepage_func(void);
unsigned int (__cdecl *__MINGW_IMP_SYMBOL(___lc_codepage_func))(void) = init_codepage_func;
unsigned int __cdecl ___lc_codepage_func (void)
{
return __MINGW_IMP_SYMBOL(___lc_codepage_func) ();
}
static unsigned int __cdecl init_codepage_func(void)
{
HMODULE msvcrt = __mingw_get_msvcrt_handle();
unsigned int (__cdecl *func)(void) = NULL;
if(msvcrt) {
func = (void*)GetProcAddress(msvcrt, "___lc_codepage_func");
if(!func) {
msvcrt__lc_codepage = (unsigned int*)GetProcAddress(msvcrt, "__lc_codepage");
if(msvcrt__lc_codepage)
func = msvcrt___lc_codepage_func;
}
}
if(!func)
func = setlocale_codepage_hack;
return (__MINGW_IMP_SYMBOL(___lc_codepage_func) = func)();
}

View File

@ -0,0 +1,77 @@
/**
* 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 <process.h>
#include <stdlib.h>
#define _EXIT_LOCK1 8
void __cdecl _lock (int _File);
void __cdecl _unlock (int _File);
int __cdecl _initialize_onexit_table(_onexit_table_t *table)
{
if (!table) return -1;
table->_first = table->_last = table->_end = NULL;
return 0;
}
int __cdecl _register_onexit_function(_onexit_table_t *table, _onexit_t func)
{
if (!table) return -1;
_lock(_EXIT_LOCK1);
if (!table->_first) {
table->_first = calloc(32, sizeof(void*));
if (!table->_first) {
_unlock(_EXIT_LOCK1);
return -1;
}
table->_last = table->_first;
table->_end = table->_first + 32;
}
if (table->_last == table->_end) {
size_t len = table->_end - table->_first;
_PVFV *new_buf = realloc(table->_first, len * sizeof(void*) * 2);
if (!new_buf) {
_unlock(_EXIT_LOCK1);
return -1;
}
table->_first = new_buf;
table->_last = new_buf + len;
table->_end = new_buf + len * 2;
}
*table->_last++ = (_PVFV)func;
_unlock(_EXIT_LOCK1);
return 0;
}
int __cdecl _execute_onexit_table(_onexit_table_t *table)
{
_PVFV *first, *last;
_lock(_EXIT_LOCK1);
first = table->_first;
last = table->_last;
_initialize_onexit_table(table);
_unlock(_EXIT_LOCK1);
if (!first) return 0;
while (--last >= first)
if (*last)
(**last)();
free(first);
return 0;
}
typeof(_initialize_onexit_table) *__MINGW_IMP_SYMBOL(_initialize_onexit_table) = _initialize_onexit_table;
typeof(_register_onexit_function) *__MINGW_IMP_SYMBOL(_register_onexit_function) = _register_onexit_function;
typeof(_execute_onexit_table) *__MINGW_IMP_SYMBOL(_execute_onexit_table) = _execute_onexit_table;

View File

@ -0,0 +1,62 @@
#define _get_output_format __dummy__get_output_format
#define _set_output_format __dummy__set_output_format
#include <windows.h>
#include <msvcrt.h>
#undef _get_output_format
#undef _set_output_format
static unsigned int last_value = 0;
typedef unsigned int (*f_get_output_format)(void);
typedef unsigned int (*f_set_output_format)(unsigned int);
static unsigned int init_set_output_format(unsigned int);
f_set_output_format __MINGW_IMP_SYMBOL(_set_output_format) = init_set_output_format;
unsigned int _set_output_format(unsigned int format);
unsigned int _set_output_format(unsigned int format)
{
return __MINGW_IMP_SYMBOL(_set_output_format)(format);
}
static unsigned int fake_set_output_format(unsigned int value)
{
return InterlockedExchange((LONG*)&last_value, value);
}
static unsigned int init_set_output_format(unsigned int format)
{
f_set_output_format sof;
sof = (f_set_output_format) GetProcAddress (__mingw_get_msvcrt_handle(), "_set_output_format");
if(!sof)
sof = fake_set_output_format;
return (__MINGW_IMP_SYMBOL(_set_output_format) = sof)(format);
}
static unsigned int init_get_output_format(void);
f_get_output_format __MINGW_IMP_SYMBOL(_get_output_format) = init_get_output_format;
unsigned int _get_output_format(void);
unsigned int _get_output_format(void)
{
return __MINGW_IMP_SYMBOL(_get_output_format)();
}
static unsigned int fake_get_output_format(void)
{
return last_value;
}
static unsigned int init_get_output_format(void)
{
f_get_output_format gof;
gof = (f_get_output_format) GetProcAddress (__mingw_get_msvcrt_handle(), "_get_output_format");
if(!gof)
gof = fake_get_output_format;
return (__MINGW_IMP_SYMBOL(_get_output_format) = gof)();
}

View File

@ -0,0 +1,18 @@
/**
* 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.
*/
#define _CRTIMP
#include <stdlib.h>
#include <windows.h>
_purecall_handler __cdecl _set_purecall_handler(_purecall_handler handler)
{
static _purecall_handler prev_handler;
return InterlockedExchangePointer((void**)&prev_handler, handler);
}
void *__MINGW_IMP_SYMBOL(_set_purecall_handler) = _set_purecall_handler;

View File

@ -0,0 +1,29 @@
/**
* 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 <process.h>
#include <windows.h>
#include <winnt.h>
#include <stdlib.h>
static _tls_callback_type callback;
static void run_callback(void)
{
if (callback)
callback(NULL, DLL_PROCESS_DETACH, 0);
callback = NULL;
}
void __cdecl _register_thread_local_exe_atexit_callback(_tls_callback_type cb)
{
callback = cb;
/* This should guarantee that the callback is called. It won't be run in the
* exact right spot as intended to, but it will be run. */
atexit(run_callback);
}
typeof(_register_thread_local_exe_atexit_callback) *__MINGW_IMP_SYMBOL(_register_thread_local_exe_atexit_callback) = _register_thread_local_exe_atexit_callback;

View File

@ -0,0 +1,46 @@
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <io.h>
static errno_t __cdecl _int_access_s (const char *, int);
static errno_t __cdecl _stub (const char *, int);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_access_s))(const char *, int) =
_stub;
static errno_t __cdecl
_stub (const char *s, int m)
{
errno_t __cdecl (*f)(const char *, int) = __MINGW_IMP_SYMBOL(_access_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(const char *, int))
GetProcAddress (__mingw_get_msvcrt_handle (), "_access_s");
if (!f)
f = _int_access_s;
__MINGW_IMP_SYMBOL(_access_s) = f;
}
return (*f)(s, m);
}
errno_t __cdecl
_access_s (const char *s, int m)
{
return _stub (s, m);
}
static errno_t __cdecl
_int_access_s (const char *s, int m)
{
if (!s || (m & ~6) != 0)
{
_access (NULL, m);
return EINVAL;
}
if (!_access (s, m))
return 0;
return errno;
}

View File

@ -0,0 +1,56 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/conio_s.h>
static errno_t __cdecl _int_cgets_s (char *, size_t, size_t *);
static errno_t __cdecl _stub (char *, size_t, size_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_cgets_s))(char *, size_t, size_t *) =
_stub;
static errno_t __cdecl
_stub (char *s, size_t l, size_t *r_len)
{
errno_t __cdecl (*f)(char *, size_t, size_t *) = __MINGW_IMP_SYMBOL(_cgets_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t, size_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_cgets_s");
if (!f)
f = _int_cgets_s;
__MINGW_IMP_SYMBOL(_cgets_s) = f;
}
return (*f)(s, l, r_len);
}
errno_t __cdecl
_cgets_s (char *s, size_t l, size_t *r_len)
{
return _stub (s, l, r_len);
}
static errno_t __cdecl
_int_cgets_s (char *s, size_t l, size_t *r_len)
{
char *h, *p;
if (s && l)
s[0] = 0;
if (!s || !l || !r_len)
{
_cgets (NULL);
return EINVAL;
}
p = (char *) alloca (l + 2);
p[0] = l;
h = _cgets (s);
if (!h)
return EINVAL;
*r_len = (size_t) p[1];
memcpy (s, &p[2], *r_len);
return 0;
}

View File

@ -0,0 +1,56 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/conio_s.h>
static errno_t __cdecl _int_cgetws_s (wchar_t *, size_t, size_t *);
static errno_t __cdecl _stub (wchar_t *, size_t, size_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_cgetws_s))(wchar_t *, size_t, size_t *) =
_stub;
static errno_t __cdecl
_stub (wchar_t *s, size_t l, size_t *r_len)
{
errno_t __cdecl (*f)(wchar_t *, size_t, size_t *) = __MINGW_IMP_SYMBOL(_cgetws_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t, size_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_cgetws_s");
if (!f)
f = _int_cgetws_s;
__MINGW_IMP_SYMBOL(_cgetws_s) = f;
}
return (*f)(s, l, r_len);
}
errno_t __cdecl
_cgetws_s (wchar_t *s, size_t l, size_t *r_len)
{
return _stub (s, l, r_len);
}
static errno_t __cdecl
_int_cgetws_s (wchar_t *s, size_t l, size_t *r_len)
{
wchar_t *h, *p;
if (s && l)
s[0] = 0;
if (!s || !l || !r_len)
{
_cgetws (NULL);
return EINVAL;
}
p = (wchar_t *) alloca ((l + 2) * sizeof (wchar_t));
p[0] = l;
h = _cgetws (s);
if (!h)
return EINVAL;
*r_len = (size_t) p[1];
memcpy (s, &p[2], *r_len);
return 0;
}

View File

@ -0,0 +1,46 @@
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <io.h>
static errno_t __cdecl _int_chsize_s (int, long long);
static errno_t __cdecl _stub (int, long long);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_chsize_s))(int, long long) =
_stub;
static errno_t __cdecl
_stub (int fd, long long sz)
{
errno_t __cdecl (*f)(int, long long) = __MINGW_IMP_SYMBOL(_chsize_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(int, long long))
GetProcAddress (__mingw_get_msvcrt_handle (), "_chsize_s");
if (!f)
f = _int_chsize_s;
__MINGW_IMP_SYMBOL(_chsize_s) = f;
}
return (*f)(fd, sz);
}
errno_t __cdecl
_chsize_s (int fd, long long sz)
{
return _stub (fd, sz);
}
static errno_t __cdecl
_int_chsize_s (int fd, long long sz)
{
if (sz > 0x7fffffffll)
{
/* We can't set file bigger as 2GB, so return EACCES. */
return (errno = EACCES);
}
if (!_chsize (fd, sz))
return 0;
return errno;
}

View File

@ -0,0 +1,56 @@
#include <float.h>
#include <errno.h>
#include <windows.h>
#include <msvcrt.h>
static errno_t __cdecl _stub(
unsigned int *currentControl,
unsigned int newControl,
unsigned int mask
);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_controlfp_s))(unsigned int *, unsigned int, unsigned int) = _stub;
errno_t __cdecl _controlfp_s(
unsigned int *currentControl,
unsigned int newControl,
unsigned int mask
){
return __MINGW_IMP_SYMBOL(_controlfp_s)(currentControl,newControl,mask);
}
static const unsigned int allflags = _MCW_DN | _MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC;
static errno_t __cdecl _int_controlfp_s(
unsigned int *currentControl,
unsigned int newControl,
unsigned int mask
){
unsigned int cont;
if(!(newControl & mask & ~allflags)){
if (currentControl) *currentControl = _controlfp( 0, 0 );
return EINVAL;
}
cont = _controlfp( newControl, mask );
if(currentControl) *currentControl = cont;
return 0;
}
static errno_t __cdecl _stub (
unsigned int *currentControl,
unsigned int newControl,
unsigned int mask
)
{
errno_t __cdecl (*f)(unsigned int *, unsigned int, unsigned int) = __MINGW_IMP_SYMBOL(_controlfp_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(unsigned int *, unsigned int, unsigned int))
GetProcAddress (__mingw_get_msvcrt_handle (), "_controlfp_s");
if (!f)
f = _int_controlfp_s;
__MINGW_IMP_SYMBOL(_controlfp_s) = f;
}
return (*f)(currentControl, newControl, mask);
}

View File

@ -0,0 +1,21 @@
#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 (*__MINGW_IMP_SYMBOL(_cprintf_s))(const char *,...) =
_cprintf_s;
int __cdecl
_cprintf_s (const char *s, ...)
{
va_list argp;
int r;
va_start (argp, s);
r = _vcprintf_s (s, argp);
va_end (argp);
return r;
}

View File

@ -0,0 +1,21 @@
#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 (*__MINGW_IMP_SYMBOL(_cprintf_s_l))(const char *, _locale_t, ...) =
_cprintf_s_l;
int __cdecl
_cprintf_s_l (const char *s, _locale_t loc, ...)
{
va_list argp;
int r;
va_start (argp, loc);
r = _vcprintf_s_l (s, loc, argp);
va_end (argp);
return r;
}

View File

@ -0,0 +1,56 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_ctime32_s (char *, size_t, const __time32_t *);
static errno_t __cdecl _stub (char *, size_t, const __time32_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_ctime32_s))(char *, size_t, const __time32_t *) =
_stub;
static errno_t __cdecl
_stub (char *d, size_t dn, const __time32_t *pt)
{
errno_t __cdecl (*f)(char *, size_t, const __time32_t *) = __MINGW_IMP_SYMBOL(_ctime32_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t, const __time32_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_ctime32_s");
if (!f)
f = _int_ctime32_s;
__MINGW_IMP_SYMBOL(_ctime32_s) = f;
}
return (*f)(d, dn, pt);
}
errno_t __cdecl
_ctime32_s (char *d, size_t dn, const __time32_t *pt)
{
return _stub (d, dn, pt);
}
static errno_t __cdecl
_int_ctime32_s (char *d, size_t dn, const __time32_t *pt)
{
struct tm ltm;
errno_t e;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (!pt)
{
errno = EINVAL;
return EINVAL;
}
if ((e = _localtime32_s (&ltm, pt)) != 0)
return e;
return asctime_s (d, dn, &ltm);
}

View File

@ -0,0 +1,56 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_ctime64_s (char *, size_t, const __time64_t *);
static errno_t __cdecl _stub (char *, size_t, const __time64_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_ctime64_s))(char *, size_t, const __time64_t *) =
_stub;
static errno_t __cdecl
_stub (char *d, size_t dn, const __time64_t *pt)
{
errno_t __cdecl (*f)(char *, size_t, const __time64_t *) = __MINGW_IMP_SYMBOL(_ctime64_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t, const __time64_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_ctime64_s");
if (!f)
f = _int_ctime64_s;
__MINGW_IMP_SYMBOL(_ctime64_s) = f;
}
return (*f)(d, dn, pt);
}
errno_t __cdecl
_ctime64_s (char *d, size_t dn, const __time64_t *pt)
{
return _stub (d, dn, pt);
}
static errno_t __cdecl
_int_ctime64_s (char *d, size_t dn, const __time64_t *pt)
{
struct tm ltm;
errno_t e;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (!pt)
{
errno = EINVAL;
return EINVAL;
}
if ((e = _localtime64_s (&ltm, pt)) != 0)
return e;
return asctime_s (d, dn, &ltm);
}

View File

@ -0,0 +1,21 @@
#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 (*__MINGW_IMP_SYMBOL(_cwprintf_s))(const wchar_t *,...) =
_cwprintf_s;
int __cdecl
_cwprintf_s (const wchar_t *s, ...)
{
va_list argp;
int r;
va_start (argp, s);
r = _vcwprintf_s (s, argp);
va_end (argp);
return r;
}

View File

@ -0,0 +1,21 @@
#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 (*__MINGW_IMP_SYMBOL(_cwprintf_s_l))(const wchar_t *, _locale_t, ...) =
_cwprintf_s_l;
int __cdecl
_cwprintf_s_l (const wchar_t *s, _locale_t loc, ...)
{
va_list argp;
int r;
va_start (argp, loc);
r = _vcwprintf_s_l (s, loc, argp);
va_end (argp);
return r;
}

View File

@ -0,0 +1,51 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_gmtime32_s (struct tm *, const __time32_t *);
static errno_t __cdecl _stub (struct tm *, const __time32_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_gmtime32_s))(struct tm *, const __time32_t *) =
_stub;
static errno_t __cdecl
_stub (struct tm *ptm, const __time32_t *pt)
{
errno_t __cdecl (*f)(struct tm *, const __time32_t *) = __MINGW_IMP_SYMBOL(_gmtime32_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(struct tm *, const __time32_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_gmtime32_s");
if (!f)
f = _int_gmtime32_s;
__MINGW_IMP_SYMBOL(_gmtime32_s) = f;
}
return (*f)(ptm, pt);
}
errno_t __cdecl
_gmtime32_s (struct tm *ptm, const __time32_t *pt)
{
return _stub (ptm, pt);
}
static errno_t __cdecl
_int_gmtime32_s (struct tm *ptm, const __time32_t *pt)
{
struct tm *ltm;
if (ptm)
memset (ptm, 0xff, sizeof (*ptm));
if (!ptm || !pt)
{
errno = EINVAL;
return EINVAL;
}
if ((ltm = _gmtime32 (pt)) == NULL)
return errno;
*ptm = *ltm;
return 0;
}

View File

@ -0,0 +1,51 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_gmtime64_s (struct tm *, const __time64_t *);
static errno_t __cdecl _stub (struct tm *, const __time64_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_gmtime64_s))(struct tm *, const __time64_t *) =
_stub;
static errno_t __cdecl
_stub (struct tm *ptm, const __time64_t *pt)
{
errno_t __cdecl (*f)(struct tm *, const __time64_t *) = __MINGW_IMP_SYMBOL(_gmtime64_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(struct tm *, const __time64_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_gmtime64_s");
if (!f)
f = _int_gmtime64_s;
__MINGW_IMP_SYMBOL(_gmtime64_s) = f;
}
return (*f)(ptm, pt);
}
errno_t __cdecl
_gmtime64_s (struct tm *ptm, const __time64_t *pt)
{
return _stub (ptm, pt);
}
static errno_t __cdecl
_int_gmtime64_s (struct tm *ptm, const __time64_t *pt)
{
struct tm *ltm;
if (ptm)
memset (ptm, 0xff, sizeof (*ptm));
if (!ptm || !pt)
{
errno = EINVAL;
return EINVAL;
}
if ((ltm = _gmtime64 (pt)) == NULL)
return errno;
*ptm = *ltm;
return 0;
}

View File

@ -0,0 +1,51 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_localtime32_s (struct tm *, const __time32_t *);
static errno_t __cdecl _stub (struct tm *, const __time32_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_localtime32_s))(struct tm *, const __time32_t *) =
_stub;
static errno_t __cdecl
_stub (struct tm *ptm, const __time32_t *pt)
{
errno_t __cdecl (*f)(struct tm *, const __time32_t *) = __MINGW_IMP_SYMBOL(_localtime32_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(struct tm *, const __time32_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_localtime32_s");
if (!f)
f = _int_localtime32_s;
__MINGW_IMP_SYMBOL(_localtime32_s) = f;
}
return (*f)(ptm, pt);
}
errno_t __cdecl
_localtime32_s (struct tm *ptm, const __time32_t *pt)
{
return _stub (ptm, pt);
}
static errno_t __cdecl
_int_localtime32_s (struct tm *ptm, const __time32_t *pt)
{
struct tm *ltm;
if (ptm)
memset (ptm, 0xff, sizeof (*ptm));
if (!ptm || !pt)
{
errno = EINVAL;
return EINVAL;
}
if ((ltm = _localtime32 (pt)) == NULL)
return errno;
*ptm = *ltm;
return 0;
}

View File

@ -0,0 +1,51 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_localtime64_s (struct tm *, const __time64_t *);
static errno_t __cdecl _stub (struct tm *, const __time64_t *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_localtime64_s))(struct tm *, const __time64_t *) =
_stub;
static errno_t __cdecl
_stub (struct tm *ptm, const __time64_t *pt)
{
errno_t __cdecl (*f)(struct tm *, const __time64_t *) = __MINGW_IMP_SYMBOL(_localtime64_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(struct tm *, const __time64_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_localtime64_s");
if (!f)
f = _int_localtime64_s;
__MINGW_IMP_SYMBOL(_localtime64_s) = f;
}
return (*f)(ptm, pt);
}
errno_t __cdecl
_localtime64_s (struct tm *ptm, const __time64_t *pt)
{
return _stub (ptm, pt);
}
static errno_t __cdecl
_int_localtime64_s (struct tm *ptm, const __time64_t *pt)
{
struct tm *ltm;
if (ptm)
memset (ptm, 0xff, sizeof (*ptm));
if (!ptm || !pt)
{
errno = EINVAL;
return EINVAL;
}
if ((ltm = _localtime64 (pt)) == NULL)
return errno;
*ptm = *ltm;
return 0;
}

View File

@ -0,0 +1,54 @@
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <io.h>
static errno_t __cdecl _int_mktemp_s (char *, size_t);
static errno_t __cdecl _stub (char *, size_t);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_mktemp_s))(char *, size_t) =
_stub;
static errno_t __cdecl
_stub (char *d, size_t dn)
{
errno_t __cdecl (*f)(char *, size_t) = __MINGW_IMP_SYMBOL(_mktemp_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "_mktemp_s");
if (!f)
f = _int_mktemp_s;
__MINGW_IMP_SYMBOL(_mktemp_s) = f;
}
return (*f)(d, dn);
}
errno_t __cdecl
_mktemp_s (char *d, size_t dn)
{
return _stub (d, dn);
}
static errno_t __cdecl
_int_mktemp_s (char *d, size_t dn)
{
size_t sz;
if (!d || !dn)
{
_mktemp (NULL);
return EINVAL;
}
sz = strnlen (d, dn);
if (sz >= dn || sz < 6)
{
d[0] = 0;
_mktemp (NULL);
return EINVAL;
}
if (_mktemp (d) != NULL)
return 0;
return errno;
}

View File

@ -0,0 +1,42 @@
#include <windows.h>
#include <io.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_sopen_s(int *, const char *, int, int, int);
static errno_t __cdecl _stub(int *, const char *, int, int, int);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_sopen_s))(int *, const char *, int, int, int) = _stub;
static errno_t __cdecl
_stub (int* pfh, const char *filename, int oflag, int shflag, int pmode)
{
errno_t __cdecl (*f)(int *, const char *, int, int, int) = __MINGW_IMP_SYMBOL(_sopen_s);
if (f == _stub) {
f = (errno_t __cdecl (*)(int *, const char *, int, int, int))
GetProcAddress (__mingw_get_msvcrt_handle (), "_sopen_s");
if (f == NULL)
f = _int_sopen_s;
__MINGW_IMP_SYMBOL(_sopen_s) = f;
}
return (*f)(pfh, filename, oflag, shflag, pmode);
}
static errno_t __cdecl _int_sopen_s(int* pfh, const char *filename, int oflag, int shflag, int pmode)
{
if (pfh == NULL || filename == NULL) {
if (pfh != NULL) *pfh = -1;
errno = EINVAL;
return EINVAL;
}
*pfh = _sopen(filename, oflag, shflag, pmode);
return errno;
}
errno_t __cdecl _sopen_s(int* pfh, const char *filename, int oflag, int shflag, int pmode)
{
return _stub (pfh, filename, oflag, shflag, pmode);
}

View File

@ -0,0 +1,68 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_strdate_s (char *, size_t);
static errno_t __cdecl _stub (char *, size_t);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_strdate_s))(char *, size_t) =
_stub;
static errno_t __cdecl
_stub (char *d, size_t dn)
{
errno_t __cdecl (*f)(char *, size_t) = __MINGW_IMP_SYMBOL(_strdate_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "_strdate_s");
if (!f)
f = _int_strdate_s;
__MINGW_IMP_SYMBOL(_strdate_s) = f;
}
return (*f)(d, dn);
}
errno_t __cdecl
_strdate_s (char *d, size_t dn)
{
return _stub (d, dn);
}
static errno_t __cdecl
_int_strdate_s (char *d, size_t dn)
{
SYSTEMTIME dt;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (dn < 9)
{
errno = ERANGE;
return ERANGE;
}
GetLocalTime (&dt);
dt.wYear %= 100;
d[0] = (char) (dt.wMonth / 10 + '0');
d[1] = (char) (dt.wMonth % 10 + '0');
d[2] = '/';
d[3] = (char) (dt.wDay / 10 + '0');
d[4] = (char) (dt.wDay % 10 + '0');
d[5] = '/';
d[6] = (char) (dt.wYear / 10 + '0');
d[7] = (char) (dt.wYear % 10 + '0');
d[8] = 0;
return 0;
}

View File

@ -0,0 +1,72 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_strtime_s (char *, size_t);
static errno_t __cdecl _stub (char *, size_t);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_strtime_s))(char *, size_t) =
_stub;
static errno_t __cdecl
_stub (char *d, size_t dn)
{
errno_t __cdecl (*f)(char *, size_t) = __MINGW_IMP_SYMBOL(_strtime_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "_strtime_s");
if (!f)
f = _int_strtime_s;
__MINGW_IMP_SYMBOL(_strtime_s) = f;
}
return (*f)(d, dn);
}
errno_t __cdecl
_strtime_s (char *d, size_t dn)
{
return _stub (d, dn);
}
static errno_t __cdecl
_int_strtime_s (char *d, size_t dn)
{
SYSTEMTIME dt;
int hours, minutes, seconds;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (dn < 9)
{
errno = ERANGE;
return ERANGE;
}
GetLocalTime (&dt);
dt.wYear %= 100;
hours = dt.wHour;
minutes = dt.wMinute;
seconds = dt.wSecond;
d[2] = d[5] = ':';
d[0] = (char) (hours / 10 + '0');
d[1] = (char) (hours % 10 + '0');
d[3] = (char) (minutes / 10 + '0');
d[4] = (char) (minutes % 10 + '0');
d[6] = (char) (seconds / 10 + '0');
d[7] = (char) (seconds % 10 + '0');
d[8] = 0;
return 0;
}

View File

@ -0,0 +1,45 @@
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <io.h>
static errno_t __cdecl _int_umask_s (int, int *);
static errno_t __cdecl _stub (int, int *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_umask_s))(int, int *) =
_stub;
static errno_t __cdecl
_stub (int m, int *pold)
{
errno_t __cdecl (*f)(int, int *) = __MINGW_IMP_SYMBOL(_umask_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(int, int *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_umask_s");
if (!f)
f = _int_umask_s;
__MINGW_IMP_SYMBOL(_umask_s) = f;
}
return (*f)(m, pold);
}
errno_t __cdecl
_umask_s (int m, int *pold)
{
return _stub (m, pold);
}
static errno_t __cdecl
_int_umask_s (int m, int *pold)
{
if (!pold)
{
errno = EINVAL;
return EINVAL;
}
*pold = _umask (m);
return 0;
}

View File

@ -0,0 +1,40 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/conio_s.h>
static int __cdecl _int_vcprintf_s (const char *, va_list);
static int __cdecl _stub (const char *, va_list);
int __cdecl (*__MINGW_IMP_SYMBOL(_vcprintf_s))(const char *, va_list) =
_stub;
static int __cdecl
_stub (const char *s, va_list argp)
{
int __cdecl (*f)(const char *, va_list) = __MINGW_IMP_SYMBOL(_vcprintf_s);
if (f == _stub)
{
f = (int __cdecl (*)(const char *, va_list))
GetProcAddress (__mingw_get_msvcrt_handle (), "_vcprintf_s");
if (!f)
f = _int_vcprintf_s;
__MINGW_IMP_SYMBOL(_vcprintf_s) = f;
}
return (*f)(s, argp);
}
int __cdecl
_vcprintf_s (const char *s, va_list argp)
{
return _stub (s, argp);
}
static int __cdecl
_int_vcprintf_s (const char *s, va_list argp)
{
return _vcprintf (s, argp);
}

View File

@ -0,0 +1,40 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/conio_s.h>
static int __cdecl _int_vcprintf_s_l (const char *, _locale_t, va_list);
static int __cdecl _stub (const char *, _locale_t, va_list);
int __cdecl (*__MINGW_IMP_SYMBOL(_vcprintf_s_l))(const char *, _locale_t, va_list) =
_stub;
static int __cdecl
_stub (const char *s, _locale_t loc, va_list argp)
{
int __cdecl (*f)(const char *, _locale_t, va_list) = __MINGW_IMP_SYMBOL(_vcprintf_s_l);
if (f == _stub)
{
f = (int __cdecl (*)(const char *, _locale_t, va_list))
GetProcAddress (__mingw_get_msvcrt_handle (), "_vcprintf_s_l");
if (!f)
f = _int_vcprintf_s_l;
__MINGW_IMP_SYMBOL(_vcprintf_s_l) = f;
}
return (*f)(s, loc, argp);
}
int __cdecl
_vcprintf_s_l (const char *s, _locale_t loc, va_list argp)
{
return _stub (s, loc, argp);
}
static int __cdecl
_int_vcprintf_s_l (const char *s, _locale_t loc, va_list argp)
{
return _vcprintf_l (s, loc, argp);
}

View File

@ -0,0 +1,40 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/wchar_s.h>
static int __cdecl _int_vcwprintf_s (const wchar_t *, va_list);
static int __cdecl _stub (const wchar_t *, va_list);
int __cdecl (*__MINGW_IMP_SYMBOL(_vcwprintf_s))(const wchar_t *, va_list) =
_stub;
static int __cdecl
_stub (const wchar_t *s, va_list argp)
{
int __cdecl (*f)(const wchar_t *, va_list) = __MINGW_IMP_SYMBOL(_vcwprintf_s);
if (f == _stub)
{
f = (int __cdecl (*)(const wchar_t *, va_list))
GetProcAddress (__mingw_get_msvcrt_handle (), "_vcwprintf_s");
if (!f)
f = _int_vcwprintf_s;
__MINGW_IMP_SYMBOL(_vcwprintf_s) = f;
}
return (*f)(s, argp);
}
int __cdecl
_vcwprintf_s (const wchar_t *s, va_list argp)
{
return _stub (s, argp);
}
static int __cdecl
_int_vcwprintf_s (const wchar_t *s, va_list argp)
{
return _vcwprintf (s, argp);
}

View File

@ -0,0 +1,40 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/wchar_s.h>
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);
int __cdecl (*__MINGW_IMP_SYMBOL(_vcwprintf_s_l))(const wchar_t *, _locale_t, va_list) =
_stub;
static int __cdecl
_stub (const wchar_t *s, _locale_t loc, va_list argp)
{
int __cdecl (*f)(const wchar_t *, _locale_t, va_list) = __MINGW_IMP_SYMBOL(_vcwprintf_s_l);
if (f == _stub)
{
f = (int __cdecl (*)(const wchar_t *, _locale_t, va_list))
GetProcAddress (__mingw_get_msvcrt_handle (), "_vcwprintf_s_l");
if (!f)
f = _int_vcwprintf_s_l;
__MINGW_IMP_SYMBOL(_vcwprintf_s_l) = f;
}
return (*f)(s, loc, argp);
}
int __cdecl
_vcwprintf_s_l (const wchar_t *s, _locale_t loc, va_list argp)
{
return _stub (s, loc, argp);
}
static int __cdecl
_int_vcwprintf_s_l (const wchar_t *s, _locale_t loc, va_list argp)
{
return _vcwprintf_l (s, loc, argp);
}

View File

@ -0,0 +1,9 @@
#define MINGW_HAS_SECURE_API 1
#include <sec_api/stdio_s.h>
int __cdecl _vscprintf_p(const char *format, va_list arglist)
{
return _vscprintf_p_l(format, NULL, arglist);
}
int __cdecl (*__MINGW_IMP_SYMBOL(_vscprintf_p))(const char *, va_list) = _vscprintf_p;

View File

@ -0,0 +1,9 @@
#define MINGW_HAS_SECURE_API 1
#include <sec_api/stdio_s.h>
int __cdecl _vscwprintf_p(const wchar_t *format, va_list arglist)
{
return _vscwprintf_p_l(format, NULL, arglist);
}
int __cdecl (*__MINGW_IMP_SYMBOL(_vscwprintf_p))(const wchar_t *, va_list) = _vscwprintf_p;

View File

@ -0,0 +1,9 @@
#define MINGW_HAS_SECURE_API 1
#include <sec_api/stdio_s.h>
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);
}
int __cdecl (*__MINGW_IMP_SYMBOL(_vswprintf_p))(wchar_t*,size_t,const wchar_t*,va_list) = _vswprintf_p;

View File

@ -0,0 +1,47 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/wchar_s.h>
static errno_t __cdecl _int_waccess_s (const wchar_t *, int);
static errno_t __cdecl _stub (const wchar_t *, int);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_waccess_s))(const wchar_t *, int) =
_stub;
static errno_t __cdecl
_stub (const wchar_t *s, int m)
{
errno_t __cdecl (*f)(const wchar_t *, int) = __MINGW_IMP_SYMBOL(_waccess_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(const wchar_t *, int))
GetProcAddress (__mingw_get_msvcrt_handle (), "_waccess_s");
if (!f)
f = _int_waccess_s;
__MINGW_IMP_SYMBOL(_waccess_s) = f;
}
return (*f)(s, m);
}
errno_t __cdecl
_waccess_s (const wchar_t *s, int m)
{
return _stub (s, m);
}
static errno_t __cdecl
_int_waccess_s (const wchar_t *s, int m)
{
if (!s || (m & ~6) != 0)
{
_waccess (NULL, m);
return EINVAL;
}
if (!_waccess (s, m))
return 0;
return errno;
}

View File

@ -0,0 +1,52 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
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 *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wasctime_s))(wchar_t *, size_t, const struct tm *) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn, const struct tm *pt)
{
errno_t __cdecl (*f)(wchar_t *, size_t, const struct tm *) = __MINGW_IMP_SYMBOL(_wasctime_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t, const struct tm *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_wasctime_s");
if (!f)
f = _int_wasctime_s;
__MINGW_IMP_SYMBOL(_wasctime_s) = f;
}
return (*f)(d, dn, pt);
}
errno_t __cdecl
_wasctime_s (wchar_t *d, size_t dn, const struct tm *pt)
{
return _stub (d, dn, pt);
}
static errno_t __cdecl
_int_wasctime_s (wchar_t *d, size_t dn, const struct tm *pt)
{
wchar_t *tmp;
size_t i;
if (d && dn)
d[0] = 0;
if (!d || dn < 26 || !pt || (tmp = _wasctime (pt)) == NULL)
{
errno = EINVAL;
return EINVAL;
}
for (i = 0; tmp[i] != 0; i++)
d[i] = tmp[i];
d[i] = 0;
return 0;
}

View File

@ -0,0 +1,56 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
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 *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wctime32_s))(wchar_t *, size_t, const __time32_t *) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn, const __time32_t *pt)
{
errno_t __cdecl (*f)(wchar_t*,size_t, const __time32_t *) = __MINGW_IMP_SYMBOL(_wctime32_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t, const __time32_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_wctime32_s");
if (!f)
f = _int_wctime32_s;
__MINGW_IMP_SYMBOL(_wctime32_s) = f;
}
return (*f)(d, dn, pt);
}
errno_t __cdecl
_wctime32_s (wchar_t *d, size_t dn, const __time32_t *pt)
{
return _stub (d, dn, pt);
}
static errno_t __cdecl
_int_wctime32_s (wchar_t *d, size_t dn, const __time32_t *pt)
{
struct tm ltm;
errno_t e;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (!pt)
{
errno = EINVAL;
return EINVAL;
}
if ((e = _localtime32_s (&ltm, pt)) != 0)
return e;
return _wasctime_s (d, dn, &ltm);
}

View File

@ -0,0 +1,56 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
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 *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wctime64_s))(wchar_t *, size_t, const __time64_t *) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn, const __time64_t *pt)
{
errno_t __cdecl (*f)(wchar_t*,size_t, const __time64_t *) = __MINGW_IMP_SYMBOL(_wctime64_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t, const __time64_t *))
GetProcAddress (__mingw_get_msvcrt_handle (), "_wctime64_s");
if (!f)
f = _int_wctime64_s;
__MINGW_IMP_SYMBOL(_wctime64_s) = f;
}
return (*f)(d, dn, pt);
}
errno_t __cdecl
_wctime64_s (wchar_t *d, size_t dn, const __time64_t *pt)
{
return _stub (d, dn, pt);
}
static errno_t __cdecl
_int_wctime64_s (wchar_t *d, size_t dn, const __time64_t *pt)
{
struct tm ltm;
errno_t e;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (!pt)
{
errno = EINVAL;
return EINVAL;
}
if ((e = _localtime64_s (&ltm, pt)) != 0)
return e;
return _wasctime_s (d, dn, &ltm);
}

View File

@ -0,0 +1,55 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/wchar_s.h>
static errno_t __cdecl _int_wmktemp_s (wchar_t *, size_t);
static errno_t __cdecl _stub (wchar_t *, size_t);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wmktemp_s))(wchar_t *, size_t) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn)
{
errno_t __cdecl (*f)(wchar_t *, size_t) = __MINGW_IMP_SYMBOL(_wmktemp_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "_wmktemp_s");
if (!f)
f = _int_wmktemp_s;
__MINGW_IMP_SYMBOL(_wmktemp_s) = f;
}
return (*f)(d, dn);
}
errno_t __cdecl
_wmktemp_s (wchar_t *d, size_t dn)
{
return _stub (d, dn);
}
static errno_t __cdecl
_int_wmktemp_s (wchar_t *d, size_t dn)
{
size_t sz;
if (!d || !dn)
{
_wmktemp (NULL);
return EINVAL;
}
sz = wcsnlen (d, dn);
if (sz >= dn || sz < 6)
{
d[0] = 0;
_wmktemp (NULL);
return EINVAL;
}
if (_wmktemp (d) != NULL)
return 0;
return errno;
}

View File

@ -0,0 +1,68 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_wstrdate_s (wchar_t *, size_t);
static errno_t __cdecl _stub (wchar_t *, size_t);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wstrdate_s))(wchar_t *, size_t) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn)
{
errno_t __cdecl (*f)(wchar_t *, size_t) = __MINGW_IMP_SYMBOL(_wstrdate_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "_wstrdate_s");
if (!f)
f = _int_wstrdate_s;
__MINGW_IMP_SYMBOL(_wstrdate_s) = f;
}
return (*f)(d, dn);
}
errno_t __cdecl
_wstrdate_s (wchar_t *d, size_t dn)
{
return _stub (d, dn);
}
static errno_t __cdecl
_int_wstrdate_s (wchar_t *d, size_t dn)
{
SYSTEMTIME dt;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (dn < 9)
{
errno = ERANGE;
return ERANGE;
}
GetLocalTime (&dt);
dt.wYear %= 100;
d[0] = (wchar_t) (dt.wMonth / 10 + '0');
d[1] = (wchar_t) (dt.wMonth % 10 + '0');
d[2] = '/';
d[3] = (wchar_t) (dt.wDay / 10 + '0');
d[4] = (wchar_t) (dt.wDay % 10 + '0');
d[5] = '/';
d[6] = (wchar_t) (dt.wYear / 10 + '0');
d[7] = (wchar_t) (dt.wYear % 10 + '0');
d[8] = 0;
return 0;
}

View File

@ -0,0 +1,71 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_wstrtime_s (wchar_t *, size_t);
static errno_t __cdecl _stub (wchar_t *, size_t);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wstrtime_s))(wchar_t *, size_t) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn)
{
errno_t __cdecl (*f)(wchar_t *, size_t) = __MINGW_IMP_SYMBOL(_wstrtime_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "_wstrtime_s");
if (!f)
f = _int_wstrtime_s;
__MINGW_IMP_SYMBOL(_wstrtime_s) = f;
}
return (*f)(d, dn);
}
errno_t __cdecl
_wstrtime_s (wchar_t *d, size_t dn)
{
return _stub (d, dn);
}
static errno_t __cdecl
_int_wstrtime_s (wchar_t *d, size_t dn)
{
SYSTEMTIME dt;
int hours, minutes, seconds;
if (!d || !dn)
{
errno = EINVAL;
return EINVAL;
}
d[0] = 0;
if (dn < 9)
{
errno = ERANGE;
return ERANGE;
}
GetLocalTime (&dt);
hours = dt.wHour;
minutes = dt.wMinute;
seconds = dt.wSecond;
d[2] = d[5] = ':';
d[0] = (wchar_t) (hours / 10 + '0');
d[1] = (wchar_t) (hours % 10 + '0');
d[3] = (wchar_t) (minutes / 10 + '0');
d[4] = (wchar_t) (minutes % 10 + '0');
d[6] = (wchar_t) (seconds / 10 + '0');
d[7] = (wchar_t) (seconds % 10 + '0');
d[8] = 0;
return 0;
}

View File

@ -0,0 +1,52 @@
#include <windows.h>
#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <msvcrt.h>
static errno_t __cdecl _int_asctime_s (char *, size_t, const struct tm *);
static errno_t __cdecl _stub (char *, size_t, const struct tm *);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(asctime_s))(char *, size_t, const struct tm *) =
_stub;
static errno_t __cdecl
_stub (char *d, size_t dn, const struct tm *pt)
{
errno_t __cdecl (*f)(char *, size_t, const struct tm *) = __MINGW_IMP_SYMBOL(asctime_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t, const struct tm *))
GetProcAddress (__mingw_get_msvcrt_handle (), "asctime_s");
if (!f)
f = _int_asctime_s;
__MINGW_IMP_SYMBOL(asctime_s) = f;
}
return (*f)(d, dn, pt);
}
errno_t __cdecl
asctime_s (char *d, size_t dn, const struct tm *pt)
{
return _stub (d, dn, pt);
}
static errno_t __cdecl
_int_asctime_s (char *d, size_t dn, const struct tm *pt)
{
char *tmp;
size_t i;
if (d && dn)
d[0] = 0;
if (!d || dn < 26 || !pt || (tmp = asctime (pt)) == NULL)
{
errno = EINVAL;
return EINVAL;
}
for (i = 0; tmp[i] != 0; i++)
d[i] = tmp[i];
d[i] = 0;
return 0;
}

View File

@ -0,0 +1,59 @@
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
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);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(memcpy_s))(void *, size_t, const void *, size_t) =
_stub;
static errno_t __cdecl
_stub (void *d, size_t dn, const void *s, size_t n)
{
errno_t __cdecl (*f)(void *, size_t, const void *, size_t) = __MINGW_IMP_SYMBOL(memcpy_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(void *, size_t, const void *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "memcpy_s");
if (!f)
f = _int_memcpy_s;
__MINGW_IMP_SYMBOL(memcpy_s) = f;
}
return (*f)(d, dn, s, n);
}
errno_t __cdecl
memcpy_s (void *d, size_t dn, const void *s, size_t n)
{
return _stub (d, dn, s, n);
}
static errno_t __cdecl
_int_memcpy_s (void *d, size_t dn, const void *s, size_t n)
{
if (!n)
return 0;
if (!d || !s)
{
if (d)
memset (d, 0, dn);
errno = EINVAL;
return EINVAL;
}
if (dn < n)
{
memset (d, 0, dn);
errno = ERANGE;
return ERANGE;
}
memcpy (d, s, n);
return 0;
}

View File

@ -0,0 +1,60 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
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);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(memmove_s))(void *, size_t, const void *, size_t) =
_stub;
static errno_t __cdecl
_stub (void *d, size_t dn, const void *s, size_t n)
{
errno_t __cdecl (*f)(void *, size_t, const void *, size_t) = __MINGW_IMP_SYMBOL(memmove_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(void *, size_t, const void *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "memmove_s");
if (!f)
f = _int_memmove_s;
__MINGW_IMP_SYMBOL(memmove_s) = f;
}
return (*f)(d, dn, s, n);
}
errno_t __cdecl
memmove_s (void *d, size_t dn, const void *s, size_t n)
{
return _stub (d, dn, s, n);
}
static errno_t __cdecl
_int_memmove_s (void *d, size_t dn, const void *s, size_t n)
{
if (!n)
return 0;
if (!d || !s)
{
if (d)
memset (d, 0, dn);
errno = EINVAL;
return EINVAL;
}
if (dn < n)
{
memset (d, 0, dn);
errno = ERANGE;
return ERANGE;
}
memmove (d, s, n);
return 0;
}

View File

@ -0,0 +1,30 @@
#define _CRT_RAND_S
#include <stdlib.h>
#include <windows.h>
#include <ntsecapi.h>
#include <errno.h>
#include <msvcrt.h>
static BOOLEAN (WINAPI *pRtlGenRandom)(void*,ULONG);
static errno_t mingw_rand_s(unsigned int *pval)
{
return !pval || !pRtlGenRandom || !pRtlGenRandom(pval, sizeof(*pval)) ? EINVAL : 0;
}
static errno_t __cdecl init_rand_s(unsigned int*);
errno_t (__cdecl *__MINGW_IMP_SYMBOL(rand_s))(unsigned int*) = init_rand_s;
static errno_t __cdecl init_rand_s(unsigned int *val)
{
int (__cdecl *func)(unsigned int*);
func = (void*)GetProcAddress(__mingw_get_msvcrt_handle(), "rand_s");
if(!func) {
func = mingw_rand_s;
pRtlGenRandom = (void*)GetProcAddress(LoadLibraryW(L"advapi32.dll"), "SystemFunction036");
}
return (__MINGW_IMP_SYMBOL(rand_s) = func)(val);
}

View File

@ -0,0 +1,20 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/stdio_s.h>
int __cdecl (*__MINGW_IMP_SYMBOL(sprintf_s))(char *, size_t, const char *,...) = sprintf_s;
int __cdecl
sprintf_s (char *_DstBuf, size_t _Size, const char *_Format, ...)
{
va_list argp;
int r;
va_start (argp, _Format);
r = vsprintf_s (_DstBuf, _Size, _Format, argp);
va_end (argp);
return r;
}

View File

@ -0,0 +1,53 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/stdio_s.h>
static errno_t __cdecl _int_strerror_s (char *, size_t, int);
static errno_t __cdecl _stub (char *, size_t, int);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(strerror_s))(char *, size_t, int) = _stub;
static errno_t __cdecl
_stub (char *buffer, size_t numberOfElements, int errnum)
{
errno_t __cdecl (*f)(char *, size_t, int) = __MINGW_IMP_SYMBOL(strerror_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(char *, size_t, int))
GetProcAddress (__mingw_get_msvcrt_handle (), "strerror_s");
if (!f)
f = _int_strerror_s;
__MINGW_IMP_SYMBOL(strerror_s) = f;
}
return (*f)(buffer, numberOfElements, errnum);
}
errno_t __cdecl
strerror_s (char *buffer, size_t numberOfElements, int errnum)
{
return _stub (buffer, numberOfElements, errnum);
}
static errno_t __cdecl
_int_strerror_s (char *buffer, size_t numberOfElements, int errnum)
{
char *errmsg = strerror(errnum);
if (!errmsg || !buffer || numberOfElements == 0)
{
errno = EINVAL;
return EINVAL;
}
if (sprintf_s(buffer, numberOfElements, "%s", errmsg) == -1)
{
errno = EINVAL;
return EINVAL;
}
return 0;
}

View File

@ -0,0 +1,41 @@
#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>
static int __cdecl _int_vsprintf_s (char *, size_t, const char *, va_list);
static int __cdecl _stub (char *, size_t, const char *, va_list);
int __cdecl (*__MINGW_IMP_SYMBOL(vsprintf_s))(char *, size_t, const char *, va_list) =
_stub;
static int __cdecl
_stub (char *_DstBuf, size_t _Size, const char *_Format, va_list _ArgList)
{
int __cdecl (*f)(char *, size_t, const char *, va_list) = __MINGW_IMP_SYMBOL(vsprintf_s);
if (f == _stub)
{
f = (int __cdecl (*)(char *, size_t, const char *, va_list))
GetProcAddress (__mingw_get_msvcrt_handle (), "vsprintf_s");
if (!f)
f = _int_vsprintf_s;
__MINGW_IMP_SYMBOL(vsprintf_s) = f;
}
return (*f)(_DstBuf, _Size, _Format, _ArgList);
}
int __cdecl
vsprintf_s (char *_DstBuf, size_t _Size, const char *_Format, va_list _ArgList)
{
return _stub (_DstBuf, _Size, _Format, _ArgList);
}
static int __cdecl
_int_vsprintf_s (char *_DstBuf, size_t _Size, const char *_Format, va_list _ArgList)
{
return __ms_vsnprintf (_DstBuf, _Size, _Format, _ArgList);
}

View File

@ -0,0 +1,61 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/wchar_s.h>
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);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(wmemcpy_s))(wchar_t *, size_t, const wchar_t *, size_t) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn, const wchar_t *s, size_t n)
{
errno_t __cdecl (*f)(wchar_t *, size_t, const wchar_t *, size_t) = __MINGW_IMP_SYMBOL(wmemcpy_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t, const wchar_t *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "wmemcpy_s");
if (!f)
f = _int_wmemcpy_s;
__MINGW_IMP_SYMBOL(wmemcpy_s) = f;
}
return (*f)(d, dn, s, n);
}
errno_t __cdecl
wmemcpy_s (wchar_t *d, size_t dn, const wchar_t *s, size_t n)
{
return _stub (d, dn, s, n);
}
static errno_t __cdecl
_int_wmemcpy_s (wchar_t *d, size_t dn, const wchar_t *s, size_t n)
{
if (!n)
return 0;
if (!d || !s)
{
if (d)
memset (d, 0, dn * sizeof (wchar_t));
errno = EINVAL;
return EINVAL;
}
if (dn < n)
{
memset (d, 0, dn * sizeof (wchar_t));
errno = ERANGE;
return ERANGE;
}
memcpy (d, s, n * sizeof (wchar_t));
return 0;
}

View File

@ -0,0 +1,61 @@
#define MINGW_HAS_SECURE_API 1
#include <windows.h>
#include <malloc.h>
#include <errno.h>
#include <msvcrt.h>
#include <sec_api/wchar_s.h>
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);
errno_t __cdecl (*__MINGW_IMP_SYMBOL(wmemmove_s))(wchar_t *, size_t, const wchar_t *, size_t) =
_stub;
static errno_t __cdecl
_stub (wchar_t *d, size_t dn, const wchar_t *s, size_t n)
{
errno_t __cdecl (*f)(wchar_t *, size_t, const wchar_t *, size_t) = __MINGW_IMP_SYMBOL(wmemmove_s);
if (f == _stub)
{
f = (errno_t __cdecl (*)(wchar_t *, size_t, const wchar_t *, size_t))
GetProcAddress (__mingw_get_msvcrt_handle (), "wmemmove_s");
if (!f)
f = _int_wmemmove_s;
__MINGW_IMP_SYMBOL(wmemmove_s) = f;
}
return (*f)(d, dn, s, n);
}
errno_t __cdecl
wmemmove_s (wchar_t *d, size_t dn, const wchar_t *s, size_t n)
{
return _stub (d, dn, s, n);
}
static errno_t __cdecl
_int_wmemmove_s (wchar_t *d, size_t dn, const wchar_t *s, size_t n)
{
if (!n)
return 0;
if (!d || !s)
{
if (d)
memset (d, 0, dn * sizeof (wchar_t));
errno = EINVAL;
return EINVAL;
}
if (dn < n)
{
memset (d, 0, dn * sizeof (wchar_t));
errno = ERANGE;
return ERANGE;
}
memmove (d, s, n * sizeof (wchar_t));
return 0;
}

View File

@ -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 <stdio.h>
FILE *__cdecl __acrt_iob_func(unsigned index)
{
return &(__iob_func()[index]);
}
typedef FILE *__cdecl (*_f__acrt_iob_func)(unsigned index);
_f__acrt_iob_func __MINGW_IMP_SYMBOL(__acrt_iob_func) = __acrt_iob_func;

View File

@ -0,0 +1,102 @@
#define _CRTIMP
#include <stdio.h>
#include <synchapi.h>
#include "internal.h"
/***
* Copy of MS functions _lock_file, _unlock_file which are missing from
* msvcrt.dll and msvcr80.dll. They are needed to atomic/lock stdio
* functions (printf, fprintf, vprintf, vfprintf). We need exactly the same
* lock that MS uses in msvcrt.dll because we can mix mingw-w64 code with
* original MS functions (puts, fputs for example).
***/
_CRTIMP void __cdecl _lock(int locknum);
_CRTIMP void __cdecl _unlock(int locknum);
#define _STREAM_LOCKS 16
#define _IOLOCKED 0x8000
/***
* _lock_file - Lock a FILE
*
*Purpose:
* Assert the lock for a stdio-level file
*
*Entry:
* pf = __piob[] entry (pointer to a FILE or _FILEX)
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
void __cdecl _lock_file( FILE *pf )
{
/*
* The way the FILE (pointed to by pf) is locked depends on whether
* it is part of _iob[] or not
*/
if ( (pf >= __acrt_iob_func(0)) && (pf <= __acrt_iob_func(_IOB_ENTRIES-1)) )
{
/*
* FILE lies in _iob[] so the lock lies in _locktable[].
*/
_lock( _STREAM_LOCKS + (int)(pf - __acrt_iob_func(0)) );
/* We set _IOLOCKED to indicate we locked the stream */
pf->_flag |= _IOLOCKED;
}
else
/*
* Not part of _iob[]. Therefore, *pf is a _FILEX and the
* lock field of the struct is an initialized critical
* section.
*/
EnterCriticalSection( &(((_FILEX *)pf)->lock) );
}
void *__MINGW_IMP_SYMBOL(_lock_file) = _lock_file;
/***
* _unlock_file - Unlock a FILE
*
*Purpose:
* Release the lock for a stdio-level file
*
*Entry:
* pf = __piob[] entry (pointer to a FILE or _FILEX)
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
void __cdecl _unlock_file( FILE *pf )
{
/*
* The way the FILE (pointed to by pf) is unlocked depends on whether
* it is part of _iob[] or not
*/
if ( (pf >= __acrt_iob_func(0)) && (pf <= __acrt_iob_func(_IOB_ENTRIES-1)) )
{
/*
* FILE lies in _iob[] so the lock lies in _locktable[].
* We reset _IOLOCKED to indicate we unlock the stream.
*/
pf->_flag &= ~_IOLOCKED;
_unlock( _STREAM_LOCKS + (int)(pf - __acrt_iob_func(0)) );
}
else
/*
* Not part of _iob[]. Therefore, *pf is a _FILEX and the
* lock field of the struct is an initialized critical
* section.
*/
LeaveCriticalSection( &(((_FILEX *)pf)->lock) );
}
void *__MINGW_IMP_SYMBOL(_unlock_file) = _unlock_file;

View File

@ -15027,9 +15027,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
break;
}
} break;
case ZigTypeIdInt:
break;
case ZigTypeIdVoid:
case ZigTypeIdBool:
case ZigTypeIdInt:
case ZigTypeIdFloat:
case ZigTypeIdPointer:
case ZigTypeIdComptimeFloat:

View File

@ -570,6 +570,96 @@ static const char *build_musl(CodeGen *parent) {
return buf_ptr(&child_gen->output_file_path);
}
static const char *msvcrt_common_src[] = {
"misc" OS_SEP "onexit_table.c",
"misc" OS_SEP "register_tls_atexit.c",
"stdio" OS_SEP "acrt_iob_func.c",
"misc" OS_SEP "_configthreadlocale.c",
"misc" OS_SEP "_get_current_locale.c",
"misc" OS_SEP "invalid_parameter_handler.c",
"misc" OS_SEP "output_format.c",
"misc" OS_SEP "purecall.c",
"secapi" OS_SEP "_access_s.c",
"secapi" OS_SEP "_cgets_s.c",
"secapi" OS_SEP "_cgetws_s.c",
"secapi" OS_SEP "_chsize_s.c",
"secapi" OS_SEP "_controlfp_s.c",
"secapi" OS_SEP "_cprintf_s.c",
"secapi" OS_SEP "_cprintf_s_l.c",
"secapi" OS_SEP "_ctime32_s.c",
"secapi" OS_SEP "_ctime64_s.c",
"secapi" OS_SEP "_cwprintf_s.c",
"secapi" OS_SEP "_cwprintf_s_l.c",
"secapi" OS_SEP "_gmtime32_s.c",
"secapi" OS_SEP "_gmtime64_s.c",
"secapi" OS_SEP "_localtime32_s.c",
"secapi" OS_SEP "_localtime64_s.c",
"secapi" OS_SEP "_mktemp_s.c",
"secapi" OS_SEP "_sopen_s.c",
"secapi" OS_SEP "_strdate_s.c",
"secapi" OS_SEP "_strtime_s.c",
"secapi" OS_SEP "_umask_s.c",
"secapi" OS_SEP "_vcprintf_s.c",
"secapi" OS_SEP "_vcprintf_s_l.c",
"secapi" OS_SEP "_vcwprintf_s.c",
"secapi" OS_SEP "_vcwprintf_s_l.c",
"secapi" OS_SEP "_vscprintf_p.c",
"secapi" OS_SEP "_vscwprintf_p.c",
"secapi" OS_SEP "_vswprintf_p.c",
"secapi" OS_SEP "_waccess_s.c",
"secapi" OS_SEP "_wasctime_s.c",
"secapi" OS_SEP "_wctime32_s.c",
"secapi" OS_SEP "_wctime64_s.c",
"secapi" OS_SEP "_wstrtime_s.c",
"secapi" OS_SEP "_wmktemp_s.c",
"secapi" OS_SEP "_wstrdate_s.c",
"secapi" OS_SEP "asctime_s.c",
"secapi" OS_SEP "memcpy_s.c",
"secapi" OS_SEP "memmove_s.c",
"secapi" OS_SEP "rand_s.c",
"secapi" OS_SEP "sprintf_s.c",
"secapi" OS_SEP "strerror_s.c",
"secapi" OS_SEP "vsprintf_s.c",
"secapi" OS_SEP "wmemcpy_s.c",
"secapi" OS_SEP "wmemmove_s.c",
"stdio" OS_SEP "mingw_lock.c",
};
static const char *msvcrt_i386_src[] = {
"misc" OS_SEP "lc_locale_func.c",
};
static const char *msvcrt_other_src[] = {
"misc" OS_SEP "__p___argv.c",
"misc" OS_SEP "__p__acmdln.c",
"misc" OS_SEP "__p__fmode.c",
"misc" OS_SEP "__p__wcmdln.c",
};
static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
CFile *c_file = allocate<CFile>(1);
c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
buf_ptr(parent->zig_lib_dir), src_path));
c_file->args.append("-DHAVE_CONFIG_H");
c_file->args.append("-D__LIBMSVCRT__");
c_file->args.append("-I");
c_file->args.append(path_from_libc(parent, "mingw" OS_SEP "include" OS_SEP));
c_file->args.append("-std=gnu99");
c_file->args.append("-D_CRTBLD");
c_file->args.append("-D_WIN32_WINNT=0x0f00");
c_file->args.append("-D__MSVCRT_VERSION__=0x700");
c_file->args.append("-isystem");
c_file->args.append(path_from_libc(parent, "include" OS_SEP "any-windows-any"));
c_file->args.append("-g");
c_file->args.append("-O2");
child_gen->c_source_files.append(c_file);
}
static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {
@ -651,6 +741,24 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
}
codegen_build_and_link(child_gen);
return buf_ptr(&child_gen->output_file_path);
} else if (strcmp(file, "msvcrt-os.lib") == 0) {
CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr);
codegen_set_out_name(child_gen, buf_create_from_str("msvcrt-os"));
for (size_t i = 0; i < array_length(msvcrt_common_src); i += 1) {
add_msvcrt_os_dep(parent, child_gen, msvcrt_common_src[i]);
}
if (parent->zig_target->arch == ZigLLVM_x86) {
for (size_t i = 0; i < array_length(msvcrt_i386_src); i += 1) {
add_msvcrt_os_dep(parent, child_gen, msvcrt_i386_src[i]);
}
} else {
for (size_t i = 0; i < array_length(msvcrt_other_src); i += 1) {
add_msvcrt_os_dep(parent, child_gen, msvcrt_other_src[i]);
}
}
codegen_build_and_link(child_gen);
return buf_ptr(&child_gen->output_file_path);
} else {
zig_unreachable();
}
@ -853,6 +961,7 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path,
}
child_gen->function_sections = true;
child_gen->want_stack_check = WantStackCheckDisabled;
codegen_build_and_link(child_gen);
return &child_gen->output_file_path;
@ -1446,7 +1555,9 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) {
}
lj->args.append(get_libc_crt_file(g, "mingw32.lib"));
lj->args.append(get_libc_crt_file(g, "msvcrt-os.lib"));
lj->args.append(get_def_lib(g, "msvcrt", "mingw" OS_SEP "lib-common" OS_SEP "msvcrt.def.in"));
lj->args.append(get_def_lib(g, "kernel32", "mingw" OS_SEP "lib-common" OS_SEP "kernel32.def.in"));
} else {
if (is_dll) {
lj->args.append(get_libc_file(g->libc, "dllcrt2.o"));

View File

@ -1,6 +1,12 @@
const builtin = @import("builtin");
const is_test = builtin.is_test;
const is_gnu = switch (builtin.abi) {
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => true,
else => false,
};
const is_mingw = builtin.os == .windows and is_gnu;
comptime {
const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;
const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
@ -231,6 +237,10 @@ comptime {
@export("___chkstk", @import("compiler_rt/stack_probe.zig").___chkstk, strong_linkage);
@export("__chkstk_ms", @import("compiler_rt/stack_probe.zig").__chkstk_ms, strong_linkage);
@export("___chkstk_ms", @import("compiler_rt/stack_probe.zig").___chkstk_ms, strong_linkage);
} else if (is_mingw) {
@export("___chkstk_ms", @import("compiler_rt/stack_probe.zig").___chkstk_ms, strong_linkage);
@export("__stack_chk_fail", __stack_chk_fail, strong_linkage);
@export("__stack_chk_guard", __stack_chk_guard, strong_linkage);
}
switch (builtin.arch) {
@ -279,6 +289,17 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
}
}
extern fn __stack_chk_fail() noreturn {
@panic("stack smashing detected");
}
extern var __stack_chk_guard: usize = blk: {
var buf = [1]u8{0} ** @sizeOf(usize);
buf[@sizeOf(usize) - 1] = 255;
buf[@sizeOf(usize) - 2] = '\n';
break :blk @bitCast(usize, buf);
};
extern fn __aeabi_unwind_cpp_pr0() void {
unreachable;
}