commit eec7ef1b877c3d08954d47a410b79d922c39d27b
parent 1acde3cb8eab299a0994f243616de4e8ee028c0a
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Tue, 18 Feb 2014 18:38:50 +0000
gmtime_r() replacement on W32, add error check in get_date_string()
Diffstat:
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -268,6 +268,18 @@ AM_CONDITIONAL(USE_PRIVATE_PLIBC_H, test x$our_private_plibc_h = x1)
AC_CHECK_FUNCS_ONCE(memmem)
AC_CHECK_FUNCS_ONCE(accept4)
+AC_MSG_CHECKING([[for gmtime_s]])
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[ #include <time.h>]], [[struct tm now; time_t t; time (&t); gmtime_s (&now, &t)]])
+ ],
+ [
+ AC_DEFINE([HAVE_GMTIME_S], [1], [Define to 1 if you have `gmtime_s' function (only for W32).])
+ AC_MSG_RESULT([[yes]])
+ ],
+ [AC_MSG_RESULT([[no]])
+ ])
+
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -663,18 +663,37 @@ get_date_string (char *date)
};
struct tm now;
time_t t;
+#if defined(_WIN32) && !defined(HAVE_GMTIME_S) && !defined(__CYGWIN__)
+ struct tm* pNow;
+#endif
+ date[0] = 0;
time (&t);
- gmtime_r (&t, &now);
- SPRINTF (date,
- "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
- days[now.tm_wday % 7],
- (unsigned int) now.tm_mday,
- mons[now.tm_mon % 12],
- (unsigned int) (1900 + now.tm_year),
- (unsigned int) now.tm_hour,
- (unsigned int) now.tm_min,
- (unsigned int) now.tm_sec);
+#if !defined(_WIN32)
+ if (NULL != gmtime_r (&t, &now))
+ {
+#elif defined(HAVE_GMTIME_S)
+ if (0 == gmtime_s (&now, &t))
+ {
+#elif defined(__CYGWIN__)
+ if (NULL != gmtime_r (&t, &now))
+ {
+#else
+ pNow = gmtime(&t);
+ if (NULL != pNow)
+ {
+ now = *pNow;
+#endif
+ sprintf (date,
+ "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
+ days[now.tm_wday % 7],
+ (unsigned int) now.tm_mday,
+ mons[now.tm_mon % 12],
+ (unsigned int) (1900 + now.tm_year),
+ (unsigned int) now.tm_hour,
+ (unsigned int) now.tm_min,
+ (unsigned int) now.tm_sec);
+ }
}