]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Use localtime_s where available to fix MSYS2 build
authorDavid Woodhouse <dwmw2@infradead.org>
Fri, 13 Sep 2019 09:43:44 +0000 (10:43 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Fri, 13 Sep 2019 09:48:57 +0000 (10:48 +0100)
Fixes: #74
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
configure.ac
pulse.c
www/changelog.xml

index 656dcf4b57e53dd8033fc0cc1df49aa27f5709b4..aa824604b71b1c360236ec5d34550cfe41536a79 100644 (file)
@@ -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 <time.h>],[[
+       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 <time.h>],[[
+       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 3456c4855d8e2eb740f11f8cb749ce492c4d84a1..0c830c8f04e6ff4f51fd95e1a7ee402b6b6e86fe 100644 (file)
--- 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));
index 285a930addb98cae76f8c43f52228e1fa3cec0eb..f74c3348e509c3e01de62e80d75c3261c7cf9b5c 100644 (file)
@@ -15,7 +15,7 @@
 <ul>
    <li><b>OpenConnect HEAD</b>
      <ul>
-       <li><i>No changelog entries yet</i></li>
+       <li>Fix Windows build with MSYS2 (<a href="https://gitlab.com/openconnect/openconnect/issues/74">#74</a>).</li>
      </ul><br/>
   </li>
   <li><b><a href="ftp://ftp.infradead.org/pub/openconnect/openconnect-8.05.tar.gz">OpenConnect v8.05</a></b>