From 9d5c6df788c8eaa3986aa78c27c896255f6dc1e9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 29 Jul 2000 22:21:10 +0000 Subject: added localtime_r() --- lib/getdate.y | 14 ++++++++++++-- lib/http.c | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/getdate.y b/lib/getdate.y index 80f10120c..bdcf9d91e 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -9,10 +9,13 @@ */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" # ifdef HAVE_ALLOCA_H # include # endif +# ifdef HAVE_TIME_H +# include +# endif #endif /* Since the code of getdate.y is not included in the Emacs executable @@ -468,6 +471,7 @@ o_merid : /* NULL */ extern struct tm *gmtime (); extern struct tm *localtime (); +extern struct tm *localtime_r (time_t *, struct tm *); extern time_t mktime (); /* Month and day table. */ @@ -918,10 +922,16 @@ curl_getdate (const char *p, const time_t *now) { struct tm tm, tm0, *tmp; time_t Start; - +#ifdef HAVE_LOCALTIME_R + struct tm keeptime; +#endif yyInput = p; Start = now ? *now : time ((time_t *) NULL); +#ifdef HAVE_LOCALTIME_R + tmp = localtime_r(&Start, &keeptime); +#else tmp = localtime (&Start); +#endif if (!tmp) return -1; yyYear = tmp->tm_year + TM_YEAR_ORIGIN; diff --git a/lib/http.c b/lib/http.c index 711775bbd..c8be1e35d 100644 --- a/lib/http.c +++ b/lib/http.c @@ -61,6 +61,7 @@ #endif #include #include + #include #ifdef HAVE_UNISTD_H #include @@ -360,7 +361,18 @@ CURLcode http(struct connectdata *conn) if(data->timecondition) { struct tm *thistime; +#ifdef HAVE_LOCALTIME_R + extern struct tm *localtime_r(time_t *, struct tm *); + /* thread-safe version */ + struct tm keeptime; + thistime = localtime_r(&data->timevalue, &keeptime); +#else thistime = localtime(&data->timevalue); +#endif + if(NULL == thistime) { + failf(data, "localtime() failed!"); + return CURLE_OUT_OF_MEMORY; + } #ifdef HAVE_STRFTIME /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ -- cgit v1.2.3