libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit c23721b4ca41ad5d70dfbce4b8a8dd11e244e397
parent 738ba14cc90436fa71d709f27ba8baa9b97897fc
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Thu,  3 Dec 2015 11:53:15 +0000

connection.c: refactor get_date_string() for clarity, distinguish
different gmtime_s() forms, support C11 gmtime_s()

Diffstat:
Mconfigure.ac | 58+++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/include/platform.h | 3+++
Msrc/microhttpd/connection.c | 29++++++++++++++---------------
Mw32/common/MHD_config.h | 4++--
4 files changed, 66 insertions(+), 28 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -450,18 +450,54 @@ if test "x$enable_socketpair" = "xyes"; then AC_DEFINE([[MHD_DONT_USE_PIPES]], [[1]], [Define to use pair of sockets instead of pipes for signaling]) fi -AC_CHECK_FUNCS_ONCE([accept4 memmem snprintf]) -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_CHECK_FUNCS_ONCE([accept4 gmtime_r memmem snprintf]) +AC_CHECK_DECL([gmtime_s], [ - 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_MSG_CHECKING([[whether gmtime_s is in C11 form]]) + AC_LINK_IFELSE( + [ AC_LANG_PROGRAM( + [[ #define __STDC_WANT_LIB_EXT1__ 1 + #include <time.h> + #ifdef __cplusplus + extern "C" + #endif + struct tm* gmtime_s(const time_t* time, struct tm* result); + ]], [[ + struct tm res; + time_t t; + gmtime_s (&t, &res); + ]]) + ], + [ + AC_DEFINE([HAVE_C11_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in C11 form.]) + AC_MSG_RESULT([[yes]]) + ], + [ + AC_MSG_RESULT([[no]]) + AC_MSG_CHECKING([[whether gmtime_s is in W32 form]]) + AC_LINK_IFELSE( + [ AC_LANG_PROGRAM( + [[ #include <time.h> + #ifdef __cplusplus + extern "C" + #endif + errno_t gmtime_s(struct tm* _tm, const time_t* time); + ]], [[ + struct tm res; + time_t t; + gmtime_s (&res, &t); + ]]) + ], + [ + AC_DEFINE([HAVE_W32_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in W32 form.]) + AC_MSG_RESULT([[yes]]) + ], + [AC_MSG_RESULT([[no]]) + ]) + ]) + ], [], + [[#define __STDC_WANT_LIB_EXT1__ 1 + #include<time.h>]]) AC_CHECK_DECLS([SOCK_NONBLOCK], [AC_DEFINE([HAVE_SOCK_NONBLOCK], [1], [SOCK_NONBLOCK is defined in a socket header])], [], diff --git a/src/include/platform.h b/src/include/platform.h @@ -81,6 +81,9 @@ #if LINUX+0 && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && ! defined(_LARGEFILE64_SOURCE) #define _LARGEFILE64_SOURCE 1 #endif +#ifdef HAVE_C11_GMTIME_S +#define __STDC_WANT_LIB_EXT1__ 1 +#endif /* HAVE_C11_GMTIME_S */ #include <stdio.h> #include <stdlib.h> diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -768,28 +768,28 @@ get_date_string (char *date) }; struct tm now; time_t t; -#if defined(_WIN32) && !defined(HAVE_GMTIME_S) && !defined(__CYGWIN__) +#if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && !defined(HAVE_GMTIME_R) struct tm* pNow; #endif date[0] = 0; time (&t); -#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)) - { +#if defined(HAVE_C11_GMTIME_S) + if (NULL == gmtime_s (&t, &now)) + return; +#elif defined(HAVE_W32_GMTIME_S) + if (0 != gmtime_s (&now, &t)) + return; +#elif defined(HAVE_GMTIME_R) + if (NULL == gmtime_r(&t, &now)) + return; #else pNow = gmtime(&t); - if (NULL != pNow) - { - now = *pNow; + if (NULL == pNow) + return; + now = *pNow; #endif - sprintf (date, + sprintf (date, "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", days[now.tm_wday % 7], (unsigned int) now.tm_mday, @@ -798,7 +798,6 @@ get_date_string (char *date) (unsigned int) now.tm_hour, (unsigned int) now.tm_min, (unsigned int) now.tm_sec); - } } diff --git a/w32/common/MHD_config.h b/w32/common/MHD_config.h @@ -65,8 +65,8 @@ /* Define to 1 if you have the `_lseeki64' function. */ #define HAVE___LSEEKI64 1 -/* Define to 1 if you have the `gmtime_s' function. */ -#define HAVE_GMTIME_S 1 +/* Define to 1 if you have the `gmtime_s' function in W32 form. */ +#define HAVE_W32_GMTIME_S 1 #if _MSC_VER >= 1900 /* snprintf() supported natively since VS2015 */ /* Define to 1 if you have the `snprintf' function. */