added localtime_r()

This commit is contained in:
Daniel Stenberg 2000-07-29 22:21:10 +00:00
parent c1ab16dabb
commit 9d5c6df788
4 changed files with 295 additions and 272 deletions

538
CHANGES

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ dnl $Id$
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_INIT(lib/urldata.h) AC_INIT(lib/urldata.h)
AM_CONFIG_HEADER(config.h src/config.h) AM_CONFIG_HEADER(config.h src/config.h)
AM_INIT_AUTOMAKE(curl,"7.0.8beta") AM_INIT_AUTOMAKE(curl,"7.0.10beta")
AM_PROG_LIBTOOL AM_PROG_LIBTOOL
dnl dnl
@ -287,6 +287,7 @@ AC_CHECK_FUNCS( socket \
gethostbyname_r \ gethostbyname_r \
gethostbyaddr \ gethostbyaddr \
gethostbyaddr_r \ gethostbyaddr_r \
localtime_r \
getservbyname \ getservbyname \
gettimeofday \ gettimeofday \
inet_addr \ inet_addr \

View File

@ -9,10 +9,13 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include "config.h"
# ifdef HAVE_ALLOCA_H # ifdef HAVE_ALLOCA_H
# include <alloca.h> # include <alloca.h>
# endif # endif
# ifdef HAVE_TIME_H
# include <time.h>
# endif
#endif #endif
/* Since the code of getdate.y is not included in the Emacs executable /* 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 *gmtime ();
extern struct tm *localtime (); extern struct tm *localtime ();
extern struct tm *localtime_r (time_t *, struct tm *);
extern time_t mktime (); extern time_t mktime ();
/* Month and day table. */ /* Month and day table. */
@ -918,10 +922,16 @@ curl_getdate (const char *p, const time_t *now)
{ {
struct tm tm, tm0, *tmp; struct tm tm, tm0, *tmp;
time_t Start; time_t Start;
#ifdef HAVE_LOCALTIME_R
struct tm keeptime;
#endif
yyInput = p; yyInput = p;
Start = now ? *now : time ((time_t *) NULL); Start = now ? *now : time ((time_t *) NULL);
#ifdef HAVE_LOCALTIME_R
tmp = localtime_r(&Start, &keeptime);
#else
tmp = localtime (&Start); tmp = localtime (&Start);
#endif
if (!tmp) if (!tmp)
return -1; return -1;
yyYear = tmp->tm_year + TM_YEAR_ORIGIN; yyYear = tmp->tm_year + TM_YEAR_ORIGIN;

View File

@ -61,6 +61,7 @@
#endif #endif
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
@ -360,7 +361,18 @@ CURLcode http(struct connectdata *conn)
if(data->timecondition) { if(data->timecondition) {
struct tm *thistime; 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); thistime = localtime(&data->timevalue);
#endif
if(NULL == thistime) {
failf(data, "localtime() failed!");
return CURLE_OUT_OF_MEMORY;
}
#ifdef HAVE_STRFTIME #ifdef HAVE_STRFTIME
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */