diff --git a/include/time.h b/include/time.h index 58409776ff18..a9baa50ff1fd 100644 --- a/include/time.h +++ b/include/time.h @@ -131,18 +131,15 @@ time_t mktime __P((struct tm *)); size_t strftime __P((char *, size_t, const char *, const struct tm *)); time_t time __P((time_t *)); -#ifdef _THREAD_SAFE -char *asctime_r __P((const struct tm *, char *)); -char *ctime_r __P((const time_t *, char *)); -struct tm *gmtime_r __P((const time_t *, struct tm *)); -struct tm *localtime_r __P((const time_t *, struct tm *)); -#endif - #ifndef _ANSI_SOURCE void tzset __P((void)); #endif /* not ANSI */ #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +char *asctime_r __P((const struct tm *, char *)); +char *ctime_r __P((const time_t *, char *)); +struct tm *gmtime_r __P((const time_t *, struct tm *)); +struct tm *localtime_r __P((const time_t *, struct tm *)); char *strptime __P((const char *, const char *, struct tm *)); char *timezone __P((int, int)); void tzsetwall __P((void)); diff --git a/lib/libc/stdtime/asctime.c b/lib/libc/stdtime/asctime.c index b9da143029eb..832f18592ff3 100644 --- a/lib/libc/stdtime/asctime.c +++ b/lib/libc/stdtime/asctime.c @@ -14,10 +14,6 @@ static char elsieid[] = "@(#)asctime.c 7.7"; #include "private.h" #include "tzfile.h" -#ifndef _THREAD_SAFE -static char *asctime_r __P((const struct tm *, char *)); -#endif - /* ** A la X3J11, with core dump avoidance. */ @@ -32,9 +28,6 @@ const struct tm * timeptr; return(asctime_r(timeptr, result)); } -#ifndef _THREAD_SAFE -static -#endif char * asctime_r(timeptr, result) const struct tm * timeptr; diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index ad227cf32029..9e130bd560e2 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -1082,19 +1082,21 @@ struct tm * const tmp; #endif /* defined TM_ZONE */ } -#ifdef _THREAD_SAFE struct tm * localtime_r(timep, p_tm) const time_t * const timep; struct tm *p_tm; { +#ifdef _THREAD_SAFE pthread_mutex_lock(&lcl_mutex); +#endif tzset(); localsub(timep, 0L, p_tm); +#ifdef _THREAD_SAFE pthread_mutex_unlock(&lcl_mutex); +#endif return(p_tm); } -#endif struct tm * localtime(timep) @@ -1214,14 +1216,12 @@ const time_t * const timep; #endif } -#ifdef _THREAD_SAFE struct tm * gmtime_r(const time_t * timep, struct tm * tm) { gmtsub(timep, 0L, tm); return(tm); } -#endif #ifdef STD_INSPIRED @@ -1350,7 +1350,6 @@ const time_t * const timep; return asctime(localtime(timep)); } -#ifdef _THREAD_SAFE char * ctime_r(timep, buf) const time_t * const timep; @@ -1359,7 +1358,6 @@ char *buf; struct tm tm; return asctime_r(localtime_r(timep, &tm), buf); } -#endif /* ** Adapted from code provided by Robert Elz, who writes: