diff --git a/CMakeLists.txt b/CMakeLists.txt index affe5fa5..30e95cf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -524,6 +524,13 @@ if(NOT WIN32) CHECK_FUNCTION_EXISTS_EX(select EVENT__HAVE_SELECT) endif() +if(WIN32) + CHECK_FUNCTION_EXISTS_EX(_gmtime64_s EVENT__HAVE__GMTIME64_S) + if (NOT EVENT__HAVE__GMTIME64_S) + CHECK_FUNCTION_EXISTS_EX(_gmtime64 EVENT__HAVE__GMTIME64) + endif() +endif() + CHECK_TYPE_SIZE("uint8_t" EVENT__HAVE_UINT8_T) CHECK_TYPE_SIZE("uint16_t" EVENT__HAVE_UINT16_T) CHECK_TYPE_SIZE("uint32_t" EVENT__HAVE_UINT32_T) diff --git a/configure.ac b/configure.ac index 835ea690..05b4d9d0 100644 --- a/configure.ac +++ b/configure.ac @@ -393,6 +393,12 @@ AC_CHECK_FUNCS([ \ getservbyname \ getrandom \ ]) + +AC_CHECK_FUNCS(_gmtime64_s, [have__gmtime64_s=yes], ) +if test "x$have__gmtime64_s" != "xyes"; then + AC_CHECK_FUNCS(_gmtime64) +fi + AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno]) AC_CACHE_CHECK( diff --git a/event-config.h.cmake b/event-config.h.cmake index 5b38b9f1..81abe3f4 100644 --- a/event-config.h.cmake +++ b/event-config.h.cmake @@ -289,6 +289,12 @@ /* Define to 1 if you have the `strtoll' function. */ #cmakedefine EVENT__HAVE_STRTOLL 1 +/* Define to 1 if you have the `_gmtime64_s' function. */ +#cmakedefine EVENT__HAVE__GMTIME64_S 1 + +/* Define to 1 if you have the `_gmtime64' function. */ +#cmakedefine EVENT__HAVE__GMTIME64 1 + /* Define to 1 if the system has the type `struct addrinfo'. */ #cmakedefine EVENT__HAVE_STRUCT_ADDRINFO 1 diff --git a/evutil_time.c b/evutil_time.c index c3a23589..c576463b 100644 --- a/evutil_time.c +++ b/evutil_time.c @@ -158,18 +158,28 @@ evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm) time_t t = time(NULL); -#ifndef _WIN32 +#if defined(EVENT__HAVE__GMTIME64_S) || !defined(_WIN32) struct tm sys; #endif /* If `tm` is null, set system's current time. */ if (tm == NULL) { -#ifdef _WIN32 - /** TODO: detect _gmtime64()/_gmtime64_s() */ - tm = gmtime(&t); -#else +#if !defined(_WIN32) gmtime_r(&t, &sys); tm = &sys; + /** detect _gmtime64()/_gmtime64_s() */ +#elif defined(EVENT__HAVE__GMTIME64_S) + errno_t err; + err = _gmtime64_s(&sys, &t); + if (err) { + event_errx(1, "Invalid argument to _gmtime64_s"); + } else { + tm = &sys; + } +#elif defined(EVENT__HAVE__GMTIME64) + tm = _gmtime64(&t); +#else + tm = gmtime(&t); #endif }