mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-25 04:09:31 +03:00
connection.c: refactor get_date_string() for clarity, distinguish
different gmtime_s() forms, support C11 gmtime_s()
This commit is contained in:
+47
-11
@@ -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])], [],
|
||||
|
||||
@@ -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>
|
||||
|
||||
+14
-15
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user