diff --git a/configure.ac b/configure.ac index 59d4fc91..cb23e2a7 100644 --- 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 ]], [[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 + #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 + #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]]) 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 index 1f1f5954..3e0d4392 100644 --- 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 #include diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 29001ac1..8b242bbf 100644 --- 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 index 77ecf5fd..fd23da2c 100644 --- 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. */