]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Fix Win32 build warnings about _putenv_s() redeclaration
authorDavid Woodhouse <dwmw2@infradead.org>
Sat, 27 Mar 2021 09:36:41 +0000 (09:36 +0000)
committerDavid Woodhouse <dwmw2@infradead.org>
Sat, 27 Mar 2021 10:04:19 +0000 (10:04 +0000)
../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 <dwmw2@infradead.org>
compat.c
configure.ac

index d1f16b8c521077a3a8559ffd3d6858d8ae9b903e..14e7202f70aa104b01310cc5a245636be0dc2dbd 100644 (file)
--- a/compat.c
+++ b/compat.c
 
 #include <string.h>
 #include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <ctype.h>
+
 #ifdef _WIN32
 #include <sec_api/stdlib_s.h> /* 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 <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
+#endif
 
 #include "openconnect-internal.h"
 
index 74ea785a608ba791d214acf456c1cf8cc49cf84a..b741b3a666166b48c3250eaf1eef04bcad4f21d4 100644 (file)
@@ -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 <sec_api/stdlib_s.h>])
+    AC_CHECK_DECL(getenv_s, [AC_DEFINE(HAVE_GETENV_S_DECL, 1, [MinGW declares getenv_s])], [], [#include <sec_api/stdlib_s.h>])
     ;;
  *darwin*)
     system_pcsc_libs="-Wl,-framework -Wl,PCSC"