--- mingw-w64-crt/Makefile.am | 2 + mingw-w64-crt/lib-common/msvcrt.def.in | 2 +- mingw-w64-crt/secapi/getenv_s.c | 61 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 mingw-w64-crt/secapi/getenv_s.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index e5ca242db7d7..15233882b4ad 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -385,6 +385,7 @@ src_msvcrt_add_x86=\ secapi/_wstrdate_s.c \ secapi/_wstrtime_s.c \ secapi/asctime_s.c \ + secapi/getenv_s.c \ secapi/memcpy_s.c \ secapi/memmove_s.c \ secapi/rand_s.c \ @@ -869,6 +870,7 @@ src_pre_msvcr80=\ misc/wcrtomb.c \ misc/wcsnlen.c \ misc/wctob.c \ + secapi/getenv_s.c \ stdio/_fseeki64.c \ stdio/_fstat64i32.c \ stdio/_ftelli64.c \ diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in b/mingw-w64-crt/lib-common/msvcrt.def.in index ab7eeed49ce7..0de1bf54b2d0 100644 --- a/mingw-w64-crt/lib-common/msvcrt.def.in +++ b/mingw-w64-crt/lib-common/msvcrt.def.in @@ -1803,7 +1803,7 @@ freopen_s fscanf_s fwprintf_s fwscanf_s -getenv_s +F_ARM_ANY(getenv_s) ; i386 and x64 getenv_s replaced by emu F_ARM_ANY(mbrlen) ; i386 and x64 mbrlen replaced by emu F_ARM_ANY(mbrtowc) ; i386 and x64 mbrtowc replaced by emu mbsdup_dbg diff --git a/mingw-w64-crt/secapi/getenv_s.c b/mingw-w64-crt/secapi/getenv_s.c new file mode 100644 index 000000000000..b2731830df98 --- /dev/null +++ b/mingw-w64-crt/secapi/getenv_s.c @@ -0,0 +1,61 @@ +/** + * 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> +#include <string.h> +#include <errno.h> + +static errno_t __cdecl emu_getenv_s(size_t *pReturnValue, char *dstBuf, rsize_t dstSize, const char *varName) +{ + const char *value; + size_t size; + + /* Only below parameter validation sets errno to EINVAL. */ + + if (!pReturnValue) + return errno = EINVAL; + + if ((!dstBuf && dstSize > 0) || (dstBuf && !dstSize)) { + *pReturnValue = 0; + return errno = EINVAL; + } + + if (!varName) { + *pReturnValue = 0; + if (dstBuf) + dstBuf[0] = '\0'; + return errno = EINVAL; + } + + /* After passing parameter validation, the errno is not changed. */ + + value = getenv(varName); + if (!value) { + *pReturnValue = 0; + if (dstBuf) + dstBuf[0] = '\0'; + return 0; + } + + size = strlen(value)+1; + *pReturnValue = size; + + if (dstBuf) { + if (size > dstSize) { + dstBuf[0] = '\0'; + return ERANGE; + } + memcpy(dstBuf, value, size); + } + + return 0; +} + +#define RETT errno_t +#define FUNC getenv_s +#define ARGS size_t *pReturnValue, char *dstBuf, rsize_t dstSize, const char *varName +#define CALL pReturnValue, dstBuf, dstSize, varName +#include "msvcrt_or_emu_glue.h" -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public