mirror of
https://github.com/ziglang/zig.git
synced 2026-01-06 13:33:21 +00:00
Upstream commit dddccbc3ef50ac52bf00723fd2f68d98140aab80 * adds ucrtbase.def.in * mingwex: replace mingw crt files with ucrt files * adds missing mingw-w64 ucrt files The rules that govern which set of files are included or excluded is contained in the logic for tools/update_mingw.zig
55 lines
1.3 KiB
C
Vendored
55 lines
1.3 KiB
C
Vendored
#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;
|
|
}
|