Skip to content

Commit

Permalink
evutil_time: detect and use _gmtime64_s()/_gmtime64()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuangongji committed Sep 19, 2019
1 parent 0cd536b commit 148d12a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,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)
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,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(
Expand Down
6 changes: 6 additions & 0 deletions event-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,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

Expand Down
20 changes: 15 additions & 5 deletions evutil_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 148d12a

Please sign in to comment.