evutil_time: detect and use _gmtime64_s()/_gmtime64()

(cherry picked from commit 148d12ad31b03a813f4ffd9df14a85392aa74130)
This commit is contained in:
yuangongji 2019-09-19 15:24:51 +08:00 committed by Azat Khuzhin
parent c169bdcbb2
commit f4a6152c3b
4 changed files with 34 additions and 5 deletions

View File

@ -524,6 +524,13 @@ if(NOT WIN32)
CHECK_FUNCTION_EXISTS_EX(select EVENT__HAVE_SELECT) CHECK_FUNCTION_EXISTS_EX(select EVENT__HAVE_SELECT)
endif() 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("uint8_t" EVENT__HAVE_UINT8_T)
CHECK_TYPE_SIZE("uint16_t" EVENT__HAVE_UINT16_T) CHECK_TYPE_SIZE("uint16_t" EVENT__HAVE_UINT16_T)
CHECK_TYPE_SIZE("uint32_t" EVENT__HAVE_UINT32_T) CHECK_TYPE_SIZE("uint32_t" EVENT__HAVE_UINT32_T)

View File

@ -393,6 +393,12 @@ AC_CHECK_FUNCS([ \
getservbyname \ getservbyname \
getrandom \ 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]) AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
AC_CACHE_CHECK( AC_CACHE_CHECK(

View File

@ -289,6 +289,12 @@
/* Define to 1 if you have the `strtoll' function. */ /* Define to 1 if you have the `strtoll' function. */
#cmakedefine EVENT__HAVE_STRTOLL 1 #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'. */ /* Define to 1 if the system has the type `struct addrinfo'. */
#cmakedefine EVENT__HAVE_STRUCT_ADDRINFO 1 #cmakedefine EVENT__HAVE_STRUCT_ADDRINFO 1

View File

@ -158,18 +158,28 @@ evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm)
time_t t = time(NULL); time_t t = time(NULL);
#ifndef _WIN32 #if defined(EVENT__HAVE__GMTIME64_S) || !defined(_WIN32)
struct tm sys; struct tm sys;
#endif #endif
/* If `tm` is null, set system's current time. */ /* If `tm` is null, set system's current time. */
if (tm == NULL) { if (tm == NULL) {
#ifdef _WIN32 #if !defined(_WIN32)
/** TODO: detect _gmtime64()/_gmtime64_s() */
tm = gmtime(&t);
#else
gmtime_r(&t, &sys); gmtime_r(&t, &sys);
tm = &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 #endif
} }