diff --git a/CMakeLists.txt b/CMakeLists.txt index a45f92f63..e94757cdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -552,6 +552,7 @@ CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64) CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64) CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME) CHECK_FUNCTION_EXISTS(localtime_r LWS_HAVE_LOCALTIME_R) +CHECK_FUNCTION_EXISTS(gmtime_r LWS_HAVE_GMTIME_R) CHECK_FUNCTION_EXISTS(ctime_r LWS_HAVE_CTIME_R) CHECK_FUNCTION_EXISTS(getgrgid_r LWS_HAVE_GETGRGID_R) CHECK_FUNCTION_EXISTS(getgrnam_r LWS_HAVE_GETGRNAM_R) diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index ff3530842..d74679fa5 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -51,6 +51,7 @@ #cmakedefine LWS_HAVE_EVP_PKEY_new_raw_private_key #cmakedefine LWS_HAVE_EXECVPE #cmakedefine LWS_HAVE_LOCALTIME_R +#cmakedefine LWS_HAVE_GMTIME_R #cmakedefine LWS_HAVE_CTIME_R #cmakedefine LWS_HAVE_GETGRGID_R #cmakedefine LWS_HAVE_GETGRNAM_R diff --git a/lib/roles/http/date.c b/lib/roles/http/date.c index 5928d8cac..0b0012b6d 100644 --- a/lib/roles/http/date.c +++ b/lib/roles/http/date.c @@ -53,7 +53,14 @@ lws_http_date_render(char *buf, size_t len, const struct tm *tm) int lws_http_date_render_from_unix(char *buf, size_t len, const time_t *t) { +#if defined(LWS_HAVE_GMTIME_R) + struct tm tmp; + struct tm *tm = gmtime_r(t, &tmp); +#else struct tm *tm = gmtime(t); +#endif + if (!tm) + return -1; if (lws_http_date_render(buf, len, tm)) return -1; diff --git a/minimal-examples/secure-streams/minimal-secure-streams-sigv4/ss-s3-ss.c b/minimal-examples/secure-streams/minimal-secure-streams-sigv4/ss-s3-ss.c index a9cce26df..b12f8f51c 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-sigv4/ss-s3-ss.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-sigv4/ss-s3-ss.c @@ -87,15 +87,15 @@ create_payload(uint8_t *buf, size_t s) static void set_time(char *t) { /*20150830T123600Z*/ - time_t rawtime; - struct tm *info; - - time(&rawtime ); - info = gmtime(&rawtime); - - strftime(t ,20,"%Y%m%dT%H%M%SZ", info); - - return; + time_t ti = time(NULL); +#if defined(LWS_HAVE_GMTIME_R) + struct tm tmp; + struct tm *tm = gmtime_r(&ti, &tmp); +#else + struct tm *tm = gmtime(&ti); +#endif + assert(tm); + strftime(t, 20, "%Y%m%dT%H%M%SZ", tm); } static void bin2hex(uint8_t *in, size_t len, char *out)