diff --git a/macros/neon.m4 b/macros/neon.m4 index a7c739af..e7f6cb6d 100644 --- a/macros/neon.m4 +++ b/macros/neon.m4 @@ -675,7 +675,7 @@ NE_LARGEFILE AC_REPLACE_FUNCS(strcasecmp) AC_CHECK_FUNCS([signal setvbuf setsockopt stpcpy poll fcntl getsockopt \ - explicit_bzero sendmsg gettimeofday]) + explicit_bzero sendmsg gettimeofday gmtime_r]) if test "x${ac_cv_func_poll}${ac_cv_header_sys_poll_h}y" = "xyesyesy"; then AC_DEFINE([NE_USE_POLL], 1, [Define if poll() should be used]) diff --git a/src/ne_dates.c b/src/ne_dates.c index 3f0c3c88..0835aa9c 100644 --- a/src/ne_dates.c +++ b/src/ne_dates.c @@ -99,17 +99,27 @@ time_t gmt_to_local_win32(void) #endif char *ne_rfc1123_date(time_t anytime) { - struct tm *gmt; + struct tm gmt; + struct tm *rv; char *ret; - gmt = gmtime(&anytime); - if (gmt == NULL) - return NULL; + +#ifdef HAVE_GMTIME_R +#warning fish + if ((rv = gmtime_r(&anytime, &gmt)) == NULL) + return NULL; +#else + if ((rv = gmtime(&anytime)) == NULL) + return NULL; + + gmt = *rv; +#endif + ret = ne_malloc(29 + 1); /* dates are 29 chars long */ ne_snprintf(ret, 30, IMFFIX_FORMAT, - rfc1123_weekdays[gmt->tm_wday], gmt->tm_mday, - short_months[gmt->tm_mon], 1900 + gmt->tm_year, - gmt->tm_hour, gmt->tm_min, gmt->tm_sec); - + rfc1123_weekdays[gmt.tm_wday], gmt.tm_mday, + short_months[gmt.tm_mon], 1900 + gmt.tm_year, + gmt.tm_hour, gmt.tm_min, gmt.tm_sec); + return ret; } diff --git a/test/util-tests.c b/test/util-tests.c index 4a8301f6..fd7cc193 100644 --- a/test/util-tests.c +++ b/test/util-tests.c @@ -26,6 +26,9 @@ #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_STDINT_H +#include +#endif #include "ne_utils.h" #include "ne_md5.h" @@ -254,6 +257,16 @@ static int bad_dates(void) BAD_DATE("asctime", ne_asctime_parse(dates[n])); } +#if SIZEOF_TIME_T == 8 && defined(INT64_MAX) + { + char *rv = ne_rfc1123_date(INT64_MAX); + + ONV(rv != NULL, + ("RFC1123 date conversion surprisingly worked for INT64_MAX: %s", + rv)); + } +#endif + return OK; }