diff options
| author | Daniel Eischen <deischen@FreeBSD.org> | 2001-01-24 13:01:12 +0000 | 
|---|---|---|
| committer | Daniel Eischen <deischen@FreeBSD.org> | 2001-01-24 13:01:12 +0000 | 
| commit | d201fe46e355212750b727061e6a7ac005267852 (patch) | |
| tree | d949d903e602687ee53252807dc4281a27c4f0c4 /lib/libc/stdtime | |
| parent | e0aa5ab7184d7449e4c2e2e65107898ad23b31f7 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdtime')
| -rw-r--r-- | lib/libc/stdtime/asctime.c | 4 | ||||
| -rw-r--r-- | lib/libc/stdtime/difftime.c | 4 | ||||
| -rw-r--r-- | lib/libc/stdtime/localtime.c | 184 | ||||
| -rw-r--r-- | lib/libc/stdtime/strftime.c | 2 | ||||
| -rw-r--r-- | lib/libc/stdtime/strptime.c | 23 | ||||
| -rw-r--r-- | lib/libc/stdtime/timelocal.c | 6 | 
6 files changed, 100 insertions, 123 deletions
diff --git a/lib/libc/stdtime/asctime.c b/lib/libc/stdtime/asctime.c index 832f18592ff3..d6e02b8324fa 100644 --- a/lib/libc/stdtime/asctime.c +++ b/lib/libc/stdtime/asctime.c @@ -1,6 +1,8 @@  /*  ** This file is in the public domain, so clarified as of  ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +* +* $FreeBSD$  */  #ifndef lint @@ -11,7 +13,9 @@ static char	elsieid[] = "@(#)asctime.c	7.7";  /*LINTLIBRARY*/ +#include "namespace.h"  #include "private.h" +#include "un-namespace.h"  #include "tzfile.h"  /* diff --git a/lib/libc/stdtime/difftime.c b/lib/libc/stdtime/difftime.c index f178524f5152..64a5ea204f15 100644 --- a/lib/libc/stdtime/difftime.c +++ b/lib/libc/stdtime/difftime.c @@ -1,6 +1,8 @@  /*  ** This file is in the public domain, so clarified as of  ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +* +* $FreeBSD$  */  #ifndef lint @@ -11,7 +13,9 @@ static char	elsieid[] = "@(#)difftime.c	7.7";  /*LINTLIBRARY*/ +#include "namespace.h"  #include "private.h" +#include "un-namespace.h"  /*  ** Algorithm courtesy Paul Eggert (eggert@twinsun.com). diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index 84a4ca9d7a19..e336414da018 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -19,16 +19,20 @@ static char	elsieid[] = "@(#)localtime.c	7.57";  /*LINTLIBRARY*/ +#include "namespace.h"  #include <sys/types.h>  #include <sys/stat.h> - +#include <fcntl.h> +#include <pthread.h>  #include "private.h" +#include "un-namespace.h" +  #include "tzfile.h" -#include "fcntl.h" -#ifdef	_THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif + +#include "libc_private.h" + +#define	_MUTEX_LOCK(x)		if (__isthreaded) _pthread_mutex_lock(x) +#define	_MUTEX_UNLOCK(x)	if (__isthreaded) _pthread_mutex_unlock(x)  /*  ** SunOS 4.1.1 headers lack O_BINARY. @@ -172,12 +176,8 @@ static struct state	gmtmem;  static char		lcl_TZname[TZ_STRLEN_MAX + 1];  static int		lcl_is_set;  static int		gmt_is_set; -#ifdef	_THREAD_SAFE -static struct pthread_mutex	_lcl_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static struct pthread_mutex	_gmt_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static pthread_mutex_t		lcl_mutex   = &_lcl_mutexd; -static pthread_mutex_t		gmt_mutex   = &_gmt_mutexd; -#endif +static pthread_mutex_t	lcl_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t	gmt_mutex = PTHREAD_MUTEX_INITIALIZER;  char *			tzname[2] = {  	wildabbr, @@ -316,7 +316,7 @@ register struct state * const	sp;  		     	return -1;  		if ((fid = _open(name, OPEN_MODE)) == -1)  			return -1; -		if ((fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) +		if ((_fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode))  			return -1;  	}  	{ @@ -929,20 +929,8 @@ struct state * const	sp;  		(void) tzparse(gmt, sp, TRUE);  } -#ifndef STD_INSPIRED -/* -** A non-static declaration of tzsetwall in a system header file -** may cause a warning about this upcoming static declaration... -*/ -static -#endif /* !defined STD_INSPIRED */ -#ifdef	_THREAD_SAFE -void -tzsetwall_basic P((void)) -#else -void -tzsetwall P((void)) -#endif +static void +tzsetwall_basic(void)  {  	if (lcl_is_set < 0)  		return; @@ -962,23 +950,16 @@ tzsetwall P((void))  	settzname();  } -#ifdef	_THREAD_SAFE  void  tzsetwall P((void))  { -	pthread_mutex_lock(&lcl_mutex); +	_MUTEX_LOCK(&lcl_mutex);  	tzsetwall_basic(); -	pthread_mutex_unlock(&lcl_mutex); +	_MUTEX_UNLOCK(&lcl_mutex);  } -#endif -#ifdef	_THREAD_SAFE  static void -tzset_basic P((void)) -#else -void -tzset P((void)) -#endif +tzset_basic(void)  {  	register const char *	name; @@ -1018,15 +999,13 @@ tzset P((void))  	settzname();  } -#ifdef	_THREAD_SAFE  void  tzset P((void))  { -	pthread_mutex_lock(&lcl_mutex); +	_MUTEX_LOCK(&lcl_mutex);  	tzset_basic(); -	pthread_mutex_unlock(&lcl_mutex); +	_MUTEX_UNLOCK(&lcl_mutex);  } -#endif  /*  ** The easy way to behave "as if no library function calls" localtime @@ -1089,14 +1068,10 @@ localtime_r(timep, p_tm)  const time_t * const	timep;  struct tm *p_tm;  { -#ifdef _THREAD_SAFE -	pthread_mutex_lock(&lcl_mutex); -#endif +	_MUTEX_LOCK(&lcl_mutex);  	tzset();  	localsub(timep, 0L, p_tm); -#ifdef _THREAD_SAFE -	pthread_mutex_unlock(&lcl_mutex); -#endif +	_MUTEX_UNLOCK(&lcl_mutex);  	return(p_tm);  } @@ -1104,36 +1079,36 @@ struct tm *  localtime(timep)  const time_t * const	timep;  { -#ifdef	_THREAD_SAFE -	static struct pthread_mutex _localtime_mutex = PTHREAD_MUTEX_STATIC_INITIALIZER; -	static pthread_mutex_t localtime_mutex = &_localtime_mutex; +	static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER;  	static pthread_key_t localtime_key = -1;  	struct tm *p_tm; -	pthread_mutex_lock(&localtime_mutex); -	if (localtime_key < 0) { -		if (pthread_key_create(&localtime_key, free) < 0) { -			pthread_mutex_unlock(&localtime_mutex); -			return(NULL); +	if (__isthreaded != 0) { +		_pthread_mutex_lock(&localtime_mutex); +		if (localtime_key < 0) { +			if (_pthread_key_create(&localtime_key, free) < 0) { +				_pthread_mutex_unlock(&localtime_mutex); +				return(NULL); +			}  		} +		_pthread_mutex_unlock(&localtime_mutex); +		p_tm = _pthread_getspecific(localtime_key); +		if (p_tm == NULL) { +			if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) +			    == NULL) +				return(NULL); +			_pthread_setspecific(localtime_key, p_tm); +		} +		_pthread_mutex_lock(&lcl_mutex); +		tzset(); +		localsub(timep, 0L, p_tm); +		_pthread_mutex_unlock(&lcl_mutex); +		return(p_tm); +	} else { +		tzset(); +		localsub(timep, 0L, &tm); +		return(&tm);  	} -	pthread_mutex_unlock(&localtime_mutex); -	p_tm = pthread_getspecific(localtime_key); -	if (p_tm == NULL) { -		if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) -			return(NULL); -		pthread_setspecific(localtime_key, p_tm); -	} -	pthread_mutex_lock(&lcl_mutex); -	tzset(); -	localsub(timep, 0L, p_tm); -	pthread_mutex_unlock(&lcl_mutex); -	return p_tm; -#else -	tzset(); -	localsub(timep, 0L, &tm); -	return &tm; -#endif  }  /* @@ -1146,9 +1121,7 @@ const time_t * const	timep;  const long		offset;  struct tm * const	tmp;  { -#ifdef	_THREAD_SAFE -	pthread_mutex_lock(&gmt_mutex); -#endif +	_MUTEX_LOCK(&gmt_mutex);  	if (!gmt_is_set) {  		gmt_is_set = TRUE;  #ifdef ALL_STATE @@ -1157,9 +1130,7 @@ struct tm * const	tmp;  #endif /* defined ALL_STATE */  			gmtload(gmtptr);  	} -#ifdef	_THREAD_SAFE -	pthread_mutex_unlock(&gmt_mutex); -#endif +	_MUTEX_UNLOCK(&gmt_mutex);  	timesub(timep, offset, gmtptr, tmp);  #ifdef TM_ZONE  	/* @@ -1186,36 +1157,37 @@ struct tm *  gmtime(timep)  const time_t * const	timep;  { -#ifdef	_THREAD_SAFE -	static struct pthread_mutex _gmtime_mutex = PTHREAD_MUTEX_STATIC_INITIALIZER; -	static pthread_mutex_t gmtime_mutex = &_gmtime_mutex; +	static pthread_mutex_t gmtime_mutex = PTHREAD_MUTEX_INITIALIZER;  	static pthread_key_t gmtime_key = -1;  	struct tm *p_tm; -	pthread_mutex_lock(&gmtime_mutex); -	if (gmtime_key < 0) { -		if (pthread_key_create(&gmtime_key, free) < 0) { -			pthread_mutex_unlock(&gmtime_mutex); -			return(NULL); +	if (__isthreaded != 0) { +		_pthread_mutex_lock(&gmtime_mutex); +		if (gmtime_key < 0) { +			if (_pthread_key_create(&gmtime_key, free) < 0) { +				_pthread_mutex_unlock(&gmtime_mutex); +				return(NULL); +			}  		} -	} -	pthread_mutex_unlock(&gmtime_mutex); -	/* -	 * Changed to follow draft 4 pthreads standard, which -	 * is what BSD currently has. -	 */ -	if ((p_tm = pthread_getspecific(gmtime_key)) == NULL) { -		if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { -			return(NULL); +		_pthread_mutex_unlock(&gmtime_mutex); +		/* +		 * Changed to follow POSIX.1 threads standard, which +		 * is what BSD currently has. +		 */ +		if ((p_tm = _pthread_getspecific(gmtime_key)) == NULL) { +			if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) +			    == NULL) { +				return(NULL); +			} +			_pthread_setspecific(gmtime_key, p_tm);  		} -		pthread_setspecific(gmtime_key, p_tm); +		gmtsub(timep, 0L, p_tm); +		return(p_tm); +	} +	else { +		gmtsub(timep, 0L, &tm); +		return(&tm);  	} -	gmtsub(timep, 0L, p_tm); -	return(p_tm); -#else -	gmtsub(timep, 0L, &tm); -	return &tm; -#endif  }  struct tm * @@ -1635,14 +1607,10 @@ mktime(tmp)  struct tm * const	tmp;  {  	time_t mktime_return_value; -#ifdef	_THREAD_SAFE -	pthread_mutex_lock(&lcl_mutex); -#endif +	_MUTEX_LOCK(&lcl_mutex);  	tzset();  	mktime_return_value = time1(tmp, localsub, 0L); -#ifdef	_THREAD_SAFE -	pthread_mutex_unlock(&lcl_mutex); -#endif +	_MUTEX_UNLOCK(&lcl_mutex);  	return(mktime_return_value);  } diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index cd506c1cbeaa..83bddc9a48c2 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -30,6 +30,7 @@ static const char	elsieid[] = "@(#)strftime.c	7.38";  #endif /* !defined NOID */  #endif /* !defined lint */ +#include "namespace.h"  #include "private.h"  #ifndef LIBC_SCCS @@ -41,6 +42,7 @@ static const char	sccsid[] = "@(#)strftime.c	5.4 (Berkeley) 3/14/89";  #include "tzfile.h"  #include <fcntl.h>  #include <sys/stat.h> +#include "un-namespace.h"  #include "timelocal.h"  static char *	_add P((const char *, char *, const char *)); diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index ca4dcefbf2b2..88d04ce8a5fd 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -64,21 +64,18 @@ static char sccsid[] = "@(#)strptime.c	0.1 (Powerdog) 94/03/27";  #endif /* !defined NOID */  #endif /* not lint */ +#include "namespace.h"  #include <time.h>  #include <ctype.h>  #include <string.h> -#ifdef	_THREAD_SAFE  #include <pthread.h> -#include "pthread_private.h" -#endif +#include "un-namespace.h" +#include "libc_private.h"  #include "timelocal.h"  static char * _strptime(const char *, const char *, struct tm *); -#ifdef	_THREAD_SAFE -static struct pthread_mutex	_gotgmt_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static pthread_mutex_t		gotgmt_mutex   = &_gotgmt_mutexd; -#endif +static pthread_mutex_t	gotgmt_mutex = PTHREAD_MUTEX_INITIALIZER;  static int got_GMT;  #define asizeof(a)	(sizeof (a) / sizeof ((a)[0])) @@ -524,21 +521,19 @@ strptime(const char *buf, const char *fmt, struct tm *tm)  {  	char *ret; -#ifdef	_THREAD_SAFE -	pthread_mutex_lock(&gotgmt_mutex); -#endif +	if (__isthreaded) +		_pthread_mutex_lock(&gotgmt_mutex);  	got_GMT = 0;  	ret = _strptime(buf, fmt, tm);  	if (ret && got_GMT) {  		time_t t = timegm(tm); -	    localtime_r(&t, tm); +		localtime_r(&t, tm);  		got_GMT = 0;  	} -#ifdef	_THREAD_SAFE -	pthread_mutex_unlock(&gotgmt_mutex); -#endif +	if (__isthreaded) +		_pthread_mutex_unlock(&gotgmt_mutex);  	return ret;  } diff --git a/lib/libc/stdtime/timelocal.c b/lib/libc/stdtime/timelocal.c index 3a810edfb523..c39b956001ba 100644 --- a/lib/libc/stdtime/timelocal.c +++ b/lib/libc/stdtime/timelocal.c @@ -26,6 +26,7 @@   * $FreeBSD$   */ +#include "namespace.h"  #include <sys/types.h>  #include <sys/stat.h>  #include <sys/syslimits.h> @@ -34,6 +35,9 @@  #include <stddef.h>  #include <stdlib.h>  #include <string.h> +#include <unistd.h> +#include "un-namespace.h" +  #include "setlocale.h"  #include "timelocal.h" @@ -158,7 +162,7 @@ __time_load_locale(const char *name)  	fd = _open(filename, O_RDONLY);  	if (fd < 0)  		goto no_locale; -	if (fstat(fd, &st) != 0) +	if (_fstat(fd, &st) != 0)  		goto bad_locale;  	if (st.st_size <= 0)  		goto bad_locale;  | 
