From: David Woodhouse Date: Fri, 13 Sep 2019 09:43:44 +0000 (+0100) Subject: Use localtime_s where available to fix MSYS2 build X-Git-Tag: v8.06~107 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2bcaee159b067f8ce73792e3a2e4a76c368c60a6;p=users%2Fdwmw2%2Fopenconnect.git Use localtime_s where available to fix MSYS2 build Fixes: #74 Signed-off-by: David Woodhouse --- diff --git a/configure.ac b/configure.ac index 656dcf4b..aa824604 100644 --- a/configure.ac +++ b/configure.ac @@ -197,6 +197,24 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([ ]) CFLAGS="$oldCFLAGS" +AC_MSG_CHECKING([For localtime_s]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ],[[ + struct tm tm; + time_t t = 0; + localtime_s(&tm, (time_t)0);]])], + [AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_LOCALTIME_S, 1, [Have localtime_s() function])], + [AC_MSG_RESULT([no])]) + +AC_MSG_CHECKING([For localtime_r]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ],[[ + struct tm tm; + time_t t = 0; + localtime_r(&t, &tm);]])], + [AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_LOCALTIME_R, 1, [Have localtime_r() function])], + [AC_MSG_RESULT([no])]) + if test "$have_win" = yes; then # Checking "properly" for __attribute__((dllimport,stdcall)) functions is non-trivial LIBS="$LIBS -lws2_32 -lshlwapi -lsecur32 -liphlpapi" diff --git a/pulse.c b/pulse.c index 3456c485..0c830c8f 100644 --- a/pulse.c +++ b/pulse.c @@ -956,8 +956,18 @@ static int pulse_request_session_kill(struct openconnect_info *vpninfo, struct o goto badlist; } - localtime_r(&when, &tm); - strftime(tmbuf, 80, "%a, %d %b %Y %H:%M:%S %Z", &tm); + if (0 +#ifdef HAVE_LOCALTIME_S + || !localtime_s(&tm, &when) +#endif +#ifdef HAVE_LOCALTIME_R + || localtime_r(&when, &tm) +#endif + ) { + strftime(tmbuf, sizeof(tmbuf), "%a, %d %b %Y %H:%M:%S %Z", &tm); + } else + snprintf(tmbuf, sizeof(tmbuf), "@%lu", (unsigned long)when); + buf_append(form_msg, " - %s from %s at %s\n", sessid, from, tmbuf); free(from); o.choices[i] = malloc(sizeof(struct oc_choice)); diff --git a/www/changelog.xml b/www/changelog.xml index 285a930a..f74c3348 100644 --- a/www/changelog.xml +++ b/www/changelog.xml @@ -15,7 +15,7 @@
  • OpenConnect HEAD
      -
    • No changelog entries yet
    • +
    • Fix Windows build with MSYS2 (#74).

  • OpenConnect v8.05