From: David Woodhouse Date: Sat, 27 Mar 2021 09:36:41 +0000 (+0000) Subject: Fix Win32 build warnings about _putenv_s() redeclaration X-Git-Tag: v8.20~343 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0d62d074883100a771f4dcae9402e2a69fe624b5;p=users%2Fdwmw2%2Fopenconnect.git Fix Win32 build warnings about _putenv_s() redeclaration ../compat.c:30:9: error: '_putenv_s' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes] 30 | errno_t _putenv_s( | ^~~~~~~~~ Signed-off-by: David Woodhouse --- diff --git a/compat.c b/compat.c index d1f16b8c..14e7202f 100644 --- a/compat.c +++ b/compat.c @@ -19,28 +19,27 @@ #include #include +#include +#include +#include + #ifdef _WIN32 #include /* errno_t, size_t */ +#ifndef HAVE_GETENV_S_DECL errno_t getenv_s( size_t *ret_required_buf_size, char *buf, size_t buf_size_in_bytes, const char *name ); +#endif +#ifndef HAVE_PUTENV_S_DECL errno_t _putenv_s( const char *varname, const char *value_string ); - -/* XX: needed to get _putenv_s, getenv_s from stdlib.h with MinGW, - * but only works on newer versions. - * https://stackoverflow.com/a/51977723 - */ -/* #define MINGW_HAS_SECURE_API 1 */ #endif -#include -#include -#include +#endif #include "openconnect-internal.h" diff --git a/configure.ac b/configure.ac index 74ea785a..b741b3a6 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,12 @@ case $host_os in system_pcsc_cflags= AC_CHECK_TOOL([WINDRES], [windres], []) AC_CHECK_TOOL([MAKENSIS], [makensis], []) + + # MINGW_HAS_SECURE_API may only work on newer MinGW: + # https://stackoverflow.com/a/51977723 + AC_DEFINE(MINGW_HAS_SECURE_API, 1, [Try to make getenv_s and _putenv_s available]) + AC_CHECK_DECL(_putenv_s, [AC_DEFINE(HAVE_PUTENV_S_DECL, 1, [MinGW declares _putenv_s])], [], [#include ]) + AC_CHECK_DECL(getenv_s, [AC_DEFINE(HAVE_GETENV_S_DECL, 1, [MinGW declares getenv_s])], [], [#include ]) ;; *darwin*) system_pcsc_libs="-Wl,-framework -Wl,PCSC"