mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
evutil_time: detect and use _gmtime64_s()/_gmtime64()
(cherry picked from commit 148d12ad31b03a813f4ffd9df14a85392aa74130)
This commit is contained in:
parent
c169bdcbb2
commit
f4a6152c3b
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user