diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2014-02-18 18:38:50 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2014-02-18 18:38:50 +0000 |
commit | eec7ef1b877c3d08954d47a410b79d922c39d27b (patch) | |
tree | 21cf94969beb6c2b9bbd4132172ea41d9c869900 | |
parent | 1acde3cb8eab299a0994f243616de4e8ee028c0a (diff) | |
download | libmicrohttpd-eec7ef1b877c3d08954d47a410b79d922c39d27b.tar.gz libmicrohttpd-eec7ef1b877c3d08954d47a410b79d922c39d27b.zip |
gmtime_r() replacement on W32, add error check in get_date_string()
-rw-r--r-- | configure.ac | 12 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 39 |
2 files changed, 41 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index 366a7864..5562a61d 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -268,6 +268,18 @@ AM_CONDITIONAL(USE_PRIVATE_PLIBC_H, test x$our_private_plibc_h = x1) | |||
268 | 268 | ||
269 | AC_CHECK_FUNCS_ONCE(memmem) | 269 | AC_CHECK_FUNCS_ONCE(memmem) |
270 | AC_CHECK_FUNCS_ONCE(accept4) | 270 | AC_CHECK_FUNCS_ONCE(accept4) |
271 | AC_MSG_CHECKING([[for gmtime_s]]) | ||
272 | AC_LINK_IFELSE( | ||
273 | [AC_LANG_PROGRAM( | ||
274 | [[ #include <time.h>]], [[struct tm now; time_t t; time (&t); gmtime_s (&now, &t)]]) | ||
275 | ], | ||
276 | [ | ||
277 | AC_DEFINE([HAVE_GMTIME_S], [1], [Define to 1 if you have `gmtime_s' function (only for W32).]) | ||
278 | AC_MSG_RESULT([[yes]]) | ||
279 | ], | ||
280 | [AC_MSG_RESULT([[no]]) | ||
281 | ]) | ||
282 | |||
271 | 283 | ||
272 | AC_COMPILE_IFELSE( | 284 | AC_COMPILE_IFELSE( |
273 | [AC_LANG_PROGRAM( | 285 | [AC_LANG_PROGRAM( |
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 26bf6cc0..fd19e112 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -663,18 +663,37 @@ get_date_string (char *date) | |||
663 | }; | 663 | }; |
664 | struct tm now; | 664 | struct tm now; |
665 | time_t t; | 665 | time_t t; |
666 | #if defined(_WIN32) && !defined(HAVE_GMTIME_S) && !defined(__CYGWIN__) | ||
667 | struct tm* pNow; | ||
668 | #endif | ||
666 | 669 | ||
670 | date[0] = 0; | ||
667 | time (&t); | 671 | time (&t); |
668 | gmtime_r (&t, &now); | 672 | #if !defined(_WIN32) |
669 | SPRINTF (date, | 673 | if (NULL != gmtime_r (&t, &now)) |
670 | "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", | 674 | { |
671 | days[now.tm_wday % 7], | 675 | #elif defined(HAVE_GMTIME_S) |
672 | (unsigned int) now.tm_mday, | 676 | if (0 == gmtime_s (&now, &t)) |
673 | mons[now.tm_mon % 12], | 677 | { |
674 | (unsigned int) (1900 + now.tm_year), | 678 | #elif defined(__CYGWIN__) |
675 | (unsigned int) now.tm_hour, | 679 | if (NULL != gmtime_r (&t, &now)) |
676 | (unsigned int) now.tm_min, | 680 | { |
677 | (unsigned int) now.tm_sec); | 681 | #else |
682 | pNow = gmtime(&t); | ||
683 | if (NULL != pNow) | ||
684 | { | ||
685 | now = *pNow; | ||
686 | #endif | ||
687 | sprintf (date, | ||
688 | "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", | ||
689 | days[now.tm_wday % 7], | ||
690 | (unsigned int) now.tm_mday, | ||
691 | mons[now.tm_mon % 12], | ||
692 | (unsigned int) (1900 + now.tm_year), | ||
693 | (unsigned int) now.tm_hour, | ||
694 | (unsigned int) now.tm_min, | ||
695 | (unsigned int) now.tm_sec); | ||
696 | } | ||
678 | } | 697 | } |
679 | 698 | ||
680 | 699 | ||