diff options
Diffstat (limited to 'libc/misc')
-rw-r--r-- | libc/misc/dirent/closedir.c | 4 | ||||
-rw-r--r-- | libc/misc/dirent/dirstream.h | 11 | ||||
-rw-r--r-- | libc/misc/dirent/readdir.c | 4 | ||||
-rw-r--r-- | libc/misc/dirent/readdir64.c | 4 | ||||
-rw-r--r-- | libc/misc/dirent/readdir64_r.c | 4 | ||||
-rw-r--r-- | libc/misc/dirent/readdir_r.c | 5 | ||||
-rw-r--r-- | libc/misc/dirent/rewinddir.c | 4 | ||||
-rw-r--r-- | libc/misc/dirent/seekdir.c | 4 | ||||
-rw-r--r-- | libc/misc/mntent/mntent.c | 14 | ||||
-rw-r--r-- | libc/misc/pthread/weaks.c | 3 | ||||
-rw-r--r-- | libc/misc/syslog/syslog.c | 42 | ||||
-rw-r--r-- | libc/misc/time/time.c | 99 | ||||
-rw-r--r-- | libc/misc/ttyent/getttyent.c | 12 | ||||
-rw-r--r-- | libc/misc/utmp/utent.c | 77 |
14 files changed, 135 insertions, 152 deletions
diff --git a/libc/misc/dirent/closedir.c b/libc/misc/dirent/closedir.c index f58857b82..3dc0bd17a 100644 --- a/libc/misc/dirent/closedir.c +++ b/libc/misc/dirent/closedir.c @@ -27,10 +27,10 @@ int closedir(DIR * dir) __set_errno(EBADF); return -1; } - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); fd = dir->dd_fd; dir->dd_fd = -1; - __pthread_mutex_unlock(&(dir->dd_lock)); + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); free(dir->dd_buf); free(dir); return close(fd); diff --git a/libc/misc/dirent/dirstream.h b/libc/misc/dirent/dirstream.h index a90ca6312..761111b9e 100644 --- a/libc/misc/dirent/dirstream.h +++ b/libc/misc/dirent/dirstream.h @@ -26,9 +26,8 @@ Cambridge, MA 02139, USA. */ #include <features.h> #include <sys/types.h> -#ifdef __UCLIBC_HAS_THREADS__ -#include <pthread.h> -#endif + +#include <bits/uClibc_mutex.h> /* For now, syscall readdir () only supports one entry at a time. It * will be changed in the future. @@ -63,11 +62,7 @@ struct __dirstream { size_t dd_max; /* lock */ -#ifdef __UCLIBC_HAS_THREADS__ - pthread_mutex_t dd_lock; -#else - void *dd_lock; -#endif + __UCLIBC_MUTEX(dd_lock); }; /* stream data from opendir() */ diff --git a/libc/misc/dirent/readdir.c b/libc/misc/dirent/readdir.c index 6fb1146eb..2fb7a7246 100644 --- a/libc/misc/dirent/readdir.c +++ b/libc/misc/dirent/readdir.c @@ -25,7 +25,7 @@ struct dirent *readdir(DIR * dir) return NULL; } - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); do { if (dir->dd_size <= dir->dd_nextloc) { @@ -51,7 +51,7 @@ struct dirent *readdir(DIR * dir) } while (de->d_ino == 0); all_done: - __pthread_mutex_unlock(&(dir->dd_lock)); + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); return de; } libc_hidden_def(readdir) diff --git a/libc/misc/dirent/readdir64.c b/libc/misc/dirent/readdir64.c index 5386ee17e..36dc35379 100644 --- a/libc/misc/dirent/readdir64.c +++ b/libc/misc/dirent/readdir64.c @@ -25,7 +25,7 @@ struct dirent64 *readdir64(DIR * dir) return NULL; } - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); do { if (dir->dd_size <= dir->dd_nextloc) { @@ -51,7 +51,7 @@ struct dirent64 *readdir64(DIR * dir) } while (de->d_ino == 0); all_done: - __pthread_mutex_unlock(&(dir->dd_lock)); + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); return de; } diff --git a/libc/misc/dirent/readdir64_r.c b/libc/misc/dirent/readdir64_r.c index b42351702..23fd8f6d9 100644 --- a/libc/misc/dirent/readdir64_r.c +++ b/libc/misc/dirent/readdir64_r.c @@ -29,7 +29,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result) } de = NULL; - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); do { if (dir->dd_size <= dir->dd_nextloc) { @@ -63,7 +63,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result) all_done: - __pthread_mutex_unlock(&(dir->dd_lock)); + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); return((de != NULL)? 0 : ret); } libc_hidden_def(readdir64_r) diff --git a/libc/misc/dirent/readdir_r.c b/libc/misc/dirent/readdir_r.c index a1d8b9a77..9493ecc0d 100644 --- a/libc/misc/dirent/readdir_r.c +++ b/libc/misc/dirent/readdir_r.c @@ -26,7 +26,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result) } de = NULL; - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); do { if (dir->dd_size <= dir->dd_nextloc) { @@ -60,8 +60,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result) all_done: - __pthread_mutex_unlock(&(dir->dd_lock)); - + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); return((de != NULL)? 0 : ret); } libc_hidden_def(readdir_r) diff --git a/libc/misc/dirent/rewinddir.c b/libc/misc/dirent/rewinddir.c index 516700183..1bbda0809 100644 --- a/libc/misc/dirent/rewinddir.c +++ b/libc/misc/dirent/rewinddir.c @@ -18,8 +18,8 @@ void rewinddir(DIR * dir) __set_errno(EBADF); return; } - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); lseek(dir->dd_fd, 0, SEEK_SET); dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0; - __pthread_mutex_unlock(&(dir->dd_lock)); + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); } diff --git a/libc/misc/dirent/seekdir.c b/libc/misc/dirent/seekdir.c index ba25ffd40..c41844856 100644 --- a/libc/misc/dirent/seekdir.c +++ b/libc/misc/dirent/seekdir.c @@ -17,8 +17,8 @@ void seekdir(DIR * dir, long int offset) __set_errno(EBADF); return; } - __pthread_mutex_lock(&(dir->dd_lock)); + __UCLIBC_MUTEX_LOCK(dir->dd_lock); dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET); dir->dd_size = dir->dd_nextloc = 0; - __pthread_mutex_unlock(&(dir->dd_lock)); + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); } diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c index 3164f6634..a5db799dc 100644 --- a/libc/misc/mntent/mntent.c +++ b/libc/misc/mntent/mntent.c @@ -8,6 +8,9 @@ #include <stdlib.h> #include <string.h> #include <mntent.h> +#include <bits/uClibc_mutex.h> + +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER); libc_hidden_proto(getmntent_r) libc_hidden_proto(setmntent) @@ -23,13 +26,6 @@ libc_hidden_proto(fgets) libc_hidden_proto(abort) libc_hidden_proto(fprintf) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; -#endif -#define LOCK __pthread_mutex_lock(&mylock) -#define UNLOCK __pthread_mutex_unlock(&mylock) - /* Reentrant version of getmntent. */ struct mntent *getmntent_r (FILE *filep, struct mntent *mnt, char *buff, int bufsize) @@ -85,7 +81,7 @@ struct mntent *getmntent(FILE * filep) struct mntent *tmp; static char *buff = NULL; static struct mntent mnt; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (!buff) { buff = malloc(BUFSIZ); @@ -94,7 +90,7 @@ struct mntent *getmntent(FILE * filep) } tmp = getmntent_r(filep, &mnt, buff, BUFSIZ); - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); return(tmp); } diff --git a/libc/misc/pthread/weaks.c b/libc/misc/pthread/weaks.c index 68b603cc5..1566846ca 100644 --- a/libc/misc/pthread/weaks.c +++ b/libc/misc/pthread/weaks.c @@ -30,11 +30,14 @@ static int __pthread_return_0 (void); static int __pthread_return_0 (void) { return 0; } +static void __pthread_return_void (void) { return; } weak_alias (__pthread_return_0, __pthread_mutex_init) weak_alias (__pthread_return_0, __pthread_mutex_lock) weak_alias (__pthread_return_0, __pthread_mutex_trylock) weak_alias (__pthread_return_0, __pthread_mutex_unlock) +weak_alias (__pthread_return_void, _pthread_cleanup_push_defer) +weak_alias (__pthread_return_void, _pthread_cleanup_pop_restore) #ifdef __UCLIBC_HAS_THREADS_NATIVE__ weak_alias (__pthread_return_0, __pthread_mutexattr_init) weak_alias (__pthread_return_0, __pthread_mutexattr_destroy) diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c index 10b8e6e58..0a5c48f86 100644 --- a/libc/misc/syslog/syslog.c +++ b/libc/misc/syslog/syslog.c @@ -104,12 +104,8 @@ libc_hidden_proto(sprintf) libc_hidden_proto(vsnprintf) libc_hidden_proto(time) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; -#endif -#define LOCK __pthread_mutex_lock(&mylock) -#define UNLOCK __pthread_mutex_unlock(&mylock) +#include <bits/uClibc_mutex.h> +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); static int LogFile = -1; /* fd for log */ @@ -120,10 +116,10 @@ static int LogFacility = LOG_USER; /* default facility code */ static int LogMask = 0xff; /* mask of priorities to be logged */ static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ -static void +static void closelog_intern(int to_default) { - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (LogFile != -1) { (void) close(LogFile); } @@ -136,7 +132,7 @@ closelog_intern(int to_default) LogFacility = LOG_USER; LogMask = 0xff; } - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); } static void @@ -153,7 +149,7 @@ openlog( const char *ident, int logstat, int logfac ) { int logType = SOCK_DGRAM; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (ident != NULL) LogTag = ident; @@ -166,16 +162,15 @@ openlog( const char *ident, int logstat, int logfac ) sizeof(SyslogAddr.sa_data)); retry: if (LogStat & LOG_NDELAY) { - if ((LogFile = socket(AF_UNIX, logType, 0)) == -1){ - UNLOCK; - return; + if ((LogFile = socket(AF_UNIX, logType, 0)) == -1) { + goto DONE; } /* fcntl(LogFile, F_SETFD, 1); */ } } if (LogFile != -1 && !connected) { - if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr) - + if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr) - sizeof(SyslogAddr.sa_data) + strlen(SyslogAddr.sa_data)) != -1) { connected = 1; @@ -194,7 +189,8 @@ retry: } } - UNLOCK; +DONE: + __UCLIBC_MUTEX_UNLOCK(mylock); } libc_hidden_def(openlog) @@ -221,7 +217,7 @@ vsyslog( int pri, const char *fmt, va_list ap ) saved_errno = errno; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); /* See if we should just throw out this message. */ if (!(LogMask & LOG_MASK(LOG_PRI(pri))) || (pri &~ (LOG_PRIMASK|LOG_FACMASK))) @@ -264,7 +260,7 @@ vsyslog( int pri, const char *fmt, va_list ap ) if (p >= end || p < head_end) { /* Returned -1 in case of error... */ static const char truncate_msg[12] = "[truncated] "; memmove(head_end + sizeof(truncate_msg), head_end, - end - head_end - sizeof(truncate_msg)); + end - head_end - sizeof(truncate_msg)); memcpy(head_end, truncate_msg, sizeof(truncate_msg)); if (p < head_end) { while (p < end && *p) { @@ -299,7 +295,7 @@ vsyslog( int pri, const char *fmt, va_list ap ) } p+=rc; } while (p <= last_chr); - if (rc >= 0) + if (rc >= 0) goto getout; /* @@ -318,10 +314,10 @@ vsyslog( int pri, const char *fmt, va_list ap ) } getout: - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(mylock); if (sigpipe == 0) sigaction (SIGPIPE, &oldaction, - (struct sigaction *) NULL); + (struct sigaction *) NULL); } libc_hidden_def(vsyslog) @@ -352,10 +348,10 @@ int setlogmask(int pmask) int omask; omask = LogMask; - LOCK; + __UCLIBC_MUTEX_LOCK(mylock); if (pmask != 0) - LogMask = pmask; - UNLOCK; + LogMask = pmask; + __UCLIBC_MUTEX_UNLOCK(mylock); return (omask); } diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c index b73fe2cce..91b4097ff 100644 --- a/libc/misc/time/time.c +++ b/libc/misc/time/time.c @@ -86,7 +86,7 @@ * NOTE: uClibc mktime behavior is different than glibc's when * the struct tm has tm_isdst == -1 and also had fields outside of * the normal ranges. - * + * * Apparently, glibc examines (at least) tm_sec and guesses the app's * intention of assuming increasing or decreasing time when entering an * ambiguous time period at the dst<->st boundaries. @@ -145,6 +145,8 @@ #include <fcntl.h> #include <unistd.h> #include <bits/uClibc_uintmaxtostr.h> +#include <bits/uClibc_mutex.h> + #ifdef __UCLIBC_HAS_WCHAR__ #include <wchar.h> @@ -246,12 +248,7 @@ typedef struct { char tzname[TZNAME_MAX+1]; } rule_struct; -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -extern pthread_mutex_t _time_tzlock attribute_hidden; -#endif -#define TZLOCK __pthread_mutex_lock(&_time_tzlock) -#define TZUNLOCK __pthread_mutex_unlock(&_time_tzlock) +__UCLIBC_MUTEX_EXTERN(_time_tzlock); extern rule_struct _time_tzinfo[2] attribute_hidden; @@ -292,16 +289,16 @@ libc_hidden_def(asctime) * }; * static char mon_name[12][3] = { * "Jan", "Feb", "Mar", "Apr", "May", "Jun", - * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" * }; * static char result[26]; - * + * * sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", - * wday_name[timeptr->tm_wday], + * wday_name[timeptr->tm_wday], * mon_name[timeptr->tm_mon], * timeptr->tm_mday, timeptr->tm_hour, - * timeptr->tm_min, timeptr->tm_sec, - * 1900 + timeptr->tm_year); + * timeptr->tm_min, timeptr->tm_sec, + * 1900 + timeptr->tm_year); * return result; * } * @@ -327,10 +324,10 @@ static const unsigned char at_data[] = { 'J', 'a', 'n', 'F', 'e', 'b', 'M', 'a', 'r', 'A', 'p', 'r', 'M', 'a', 'y', 'J', 'u', 'n', 'J', 'u', 'l', 'A', 'u', 'g', - 'S', 'e', 'p', 'O', 'c', 't', 'N', 'o', 'v', 'D', 'e', 'c', + 'S', 'e', 'p', 'O', 'c', 't', 'N', 'o', 'v', 'D', 'e', 'c', #ifdef SAFE_ASCTIME_R - '?', '?', '?', + '?', '?', '?', #endif ' ', '?', '?', '?', ' ', '0', @@ -605,13 +602,13 @@ libc_hidden_def(localtime) struct tm *localtime_r(register const time_t *__restrict timer, register struct tm *__restrict result) { - TZLOCK; + __UCLIBC_MUTEX_LOCK(_time_tzlock); _time_tzset(*timer < new_rule_starts); __time_localtime_tzi(timer, result, _time_tzinfo); - TZUNLOCK; + __UCLIBC_MUTEX_UNLOCK(_time_tzlock); return result; } @@ -666,7 +663,7 @@ static const char *lookup_tzname(const char *key) static const unsigned char day_cor[] = { /* non-leap */ 31, 31, 34, 34, 35, 35, 36, 36, 36, 37, 37, 38, 38 -/* 0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7 */ +/* 0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7 */ /* 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 */ }; @@ -1052,7 +1049,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, p = format; count = maxsize; - LOOP: +LOOP: if (!count) { return 0; } @@ -1115,7 +1112,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, goto LOOP; } - o = spec + 26; /* set to "????" */ + o = ((const char *) spec) + 26; /* set to "????" */ if ((code & MASK_SPEC) == CALC_SPEC) { if (*p == 's') { @@ -1151,7 +1148,6 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, #ifdef __UCLIBC_HAS_TM_EXTENSIONS__ -#define RSP_TZUNLOCK ((void) 0) # ifdef __USE_BSD # define RSP_TZNAME timeptr->tm_zone # define RSP_GMT_OFFSET (-timeptr->tm_gmtoff) @@ -1162,11 +1158,10 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, #else -#define RSP_TZUNLOCK TZUNLOCK #define RSP_TZNAME rsp->tzname #define RSP_GMT_OFFSET rsp->gmt_offset - TZLOCK; + __UCLIBC_MUTEX_LOCK(_time_tzlock); rsp = _time_tzinfo; if (timeptr->tm_isdst > 0) { @@ -1197,24 +1192,30 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, } #endif o_count = SIZE_MAX; - RSP_TZUNLOCK; +#ifdef __UCLIBC_HAS_TM_EXTENSIONS__ goto OUTPUT; +#endif } else { /* z */ *s = '+'; if ((tzo = -RSP_GMT_OFFSET) < 0) { tzo = -tzo; *s = '-'; } - RSP_TZUNLOCK; ++s; --count; i = tzo / 60; field_val = ((i / 60) * 100) + (i % 60); - + i = 16 + 6; /* 0-fill, width = 4 */ } - +#ifdef __UCLIBC_HAS_TM_EXTENSIONS__ +#else + __UCLIBC_MUTEX_UNLOCK(_time_tzlock); + if (*p == 'Z') { + goto OUTPUT; + } +#endif } else { /* TODO: don't need year for U, W */ for (i=0 ; i < 3 ; i++) { @@ -1286,7 +1287,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, field_val += 7; } } - + if ((code & MASK_SPEC) == STRING_SPEC) { o_count = SIZE_MAX; field_val += spec[STRINGS_NL_ITEM_START + (code & 0xf)]; @@ -1304,7 +1305,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize, } } - OUTPUT: +OUTPUT: ++p; while (o_count && count && *o) { *s++ = *o++; @@ -1506,7 +1507,7 @@ char *__XL_NPP(strptime)(const char *__restrict buf, const char *__restrict form lvl = 0; p = format; - LOOP: +LOOP: if (!*p) { if (lvl == 0) { /* Done. */ if (fields[6] == 7) { /* Cleanup for %u here since just once. */ @@ -1752,9 +1753,7 @@ int daylight = 0; long timezone = 0; char *tzname[2] = { (char *) UTC, (char *) (UTC-1) }; -#ifdef __UCLIBC_HAS_THREADS__ -attribute_hidden pthread_mutex_t _time_tzlock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; -#endif +__UCLIBC_MUTEX_INIT(_time_tzlock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); rule_struct _time_tzinfo[2]; @@ -1827,7 +1826,7 @@ static const char *getnumber(register const char *e, int *pn) #ifdef __UCLIBC_HAS_TZ_FILE__ #ifndef __UCLIBC_HAS_TZ_FILE_READ_MANY__ -static int TZ_file_read; /* Let BSS initialization set this to 0. */ +static int TZ_file_read; /* Let BSS initialization set this to 0. */ #endif /* __UCLIBC_HAS_TZ_FILE_READ_MANY__ */ static char *read_TZ_file(char *buf) @@ -1858,7 +1857,7 @@ static char *read_TZ_file(char *buf) ++TZ_file_read; #endif /* __UCLIBC_HAS_TZ_FILE_READ_MANY__ */ } else { - ERROR: +ERROR: p = NULL; } close(fd); @@ -1893,7 +1892,7 @@ void _time_tzset(int use_old_rules) static char oldval[TZ_BUFLEN]; /* BSS-zero'd. */ #endif /* __UCLIBC_HAS_TZ_CACHING__ */ - TZLOCK; + __UCLIBC_MUTEX_LOCK(_time_tzlock); e = getenv(TZ); /* TZ env var always takes precedence. */ @@ -1918,7 +1917,7 @@ void _time_tzset(int use_old_rules) && !(e = read_TZ_file(buf)) /* and no file or invalid file */ #endif /* __UCLIBC_HAS_TZ_FILE__ */ ) || !*e) { /* or set to empty string. */ - ILLEGAL: /* TODO: Clean up the following... */ +ILLEGAL: /* TODO: Clean up the following... */ #ifdef __UCLIBC_HAS_TZ_CACHING__ *oldval = 0; /* Set oldval to an empty string. */ #endif /* __UCLIBC_HAS_TZ_CACHING__ */ @@ -1940,10 +1939,10 @@ void _time_tzset(int use_old_rules) * to the empty string anyway. */ strncpy(oldval, e, TZ_BUFLEN); #endif /* __UCLIBC_HAS_TZ_CACHING__ */ - + count = 0; new_rules[1].tzname[0] = 0; - LOOP: +LOOP: /* Get std or dst name. */ c = 0; if (*e == '<') { @@ -1989,7 +1988,7 @@ void _time_tzset(int use_old_rules) if (*s == '-') { off = -off; /* Save off in case needed for dst default. */ } - SKIP_OFFSET: +SKIP_OFFSET: new_rules[count].gmt_offset = off; if (!count) { @@ -2002,7 +2001,7 @@ void _time_tzset(int use_old_rules) count = 0; if (!*e) { /* No rules so default to US rules. */ e = use_old_rules ? DEFAULT_RULES : DEFAULT_2007_RULES; -#ifdef DEBUG_TZSET +#ifdef DEBUG_TZSET if (e == DEFAULT_RULES) printf("tzset: Using old rules.\n"); else if (e == DEFAULT_2007_RULES) @@ -2061,16 +2060,16 @@ void _time_tzset(int use_old_rules) } memcpy(_time_tzinfo, new_rules, sizeof(new_rules)); - DONE: +DONE: tzname[0] = _time_tzinfo[0].tzname; tzname[1] = _time_tzinfo[1].tzname; daylight = !!_time_tzinfo[1].tzname[0]; timezone = _time_tzinfo[0].gmt_offset; #if defined(__UCLIBC_HAS_TZ_FILE__) || defined(__UCLIBC_HAS_TZ_CACHING__) - FAST_DONE: +FAST_DONE: #endif - TZUNLOCK; + __UCLIBC_MUTEX_UNLOCK(_time_tzlock); } libc_hidden_def(tzset) #endif @@ -2171,7 +2170,7 @@ struct tm attribute_hidden *_time_t2tm(const time_t *__restrict timer, ++v; /* Change to days since 1/1/1601 so that for 32 bit time_t * values, we'll have t >= 0. This should be changed for - * archs with larger time_t types. + * archs with larger time_t types. * Also, correct for offset since a multiple of 7. */ /* TODO: Does this still work on archs with time_t > 32 bits? */ @@ -2277,13 +2276,13 @@ time_t attribute_hidden _time_mktime(struct tm *timeptr, int store_on_success) { time_t t; - TZLOCK; + __UCLIBC_MUTEX_LOCK(_time_tzlock); tzset(); t = _time_mktime_tzi(timeptr, store_on_success, _time_tzinfo); - TZUNLOCK; + __UCLIBC_MUTEX_UNLOCK(_time_tzlock); return t; } @@ -2336,7 +2335,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes if (__isleap(d)) { s += 11; } - + p[7] = 0; d = p[4]; while (d) { @@ -2355,7 +2354,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes days = -719163L + ((long)d)*365 + ((d/4) - (d/100) + (d/400) + p[3] + p[7]); secs = p[0] + 60*( p[1] + 60*((long)(p[2])) ) + tzi[default_dst].gmt_offset; - DST_CORRECT: +DST_CORRECT: if (secs < 0) { secs += 120009600L; days -= 1389; @@ -2375,7 +2374,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes + 24*(((146073L * ((long long)(p[6])) + d) + p[3]) + p[7]))); - DST_CORRECT: +DST_CORRECT: if (((unsigned long long)(secs - LONG_MIN)) > (((unsigned long long)LONG_MAX) - LONG_MIN) ) { @@ -2408,7 +2407,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes } - DONE: +DONE: return t; } diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c index 89c39876f..c9c68f1cc 100644 --- a/libc/misc/ttyent/getttyent.c +++ b/libc/misc/ttyent/getttyent.c @@ -126,6 +126,7 @@ struct ttyent * getttyent(void) register int c; register char *p; static char *line = NULL; + struct ttyent *retval = NULL; if (!tf && !setttyent()) return (NULL); @@ -140,8 +141,7 @@ struct ttyent * getttyent(void) for (;;) { if (!fgets_unlocked(p = line, BUFSIZ, tf)) { - __STDIO_ALWAYS_THREADUNLOCK(tf); - return (NULL); + goto DONE; } /* skip lines that are too big */ if (!strchr(p, '\n')) { @@ -184,8 +184,6 @@ struct ttyent * getttyent(void) else break; } - /* We can release the lock only here since `zapchar' is global. */ - __STDIO_ALWAYS_THREADUNLOCK(tf); if (zapchar == '#' || *p == '#') while ((c = *++p) == ' ' || c == '\t') @@ -195,7 +193,11 @@ struct ttyent * getttyent(void) tty.ty_comment = 0; if ((p = strchr(p, '\n'))) *p = '\0'; - return (&tty); + retval = &tty; + + DONE: + __STDIO_ALWAYS_THREADUNLOCK(tf); + return retval; } libc_hidden_def(getttyent) diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 57719ba68..daa68d24e 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -5,7 +5,7 @@ Note that because of the way this stupid stupid standard works, you have to call endutent() to close the file even if you've not called - setutent -- getutid and family use the same file descriptor. + setutent -- getutid and family use the same file descriptor. Modified by Erik Andersen for uClibc... */ @@ -30,12 +30,8 @@ libc_hidden_proto(fcntl) libc_hidden_proto(close) libc_hidden_proto(lseek) -#ifdef __UCLIBC_HAS_THREADS__ -# include <pthread.h> -static pthread_mutex_t utmplock = PTHREAD_MUTEX_INITIALIZER; -#endif -#define LOCK __pthread_mutex_lock(&utmplock) -#define UNLOCK __pthread_mutex_unlock(&utmplock) +#include <bits/uClibc_mutex.h> +__UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); @@ -75,9 +71,9 @@ bummer: libc_hidden_proto(setutent) void setutent(void) { - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); __setutent(); - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(utmplock); } libc_hidden_def(setutent) @@ -93,7 +89,7 @@ static struct utmp *__getutent(int utmp_fd) return NULL; } - if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp)) + if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp)) { ret = &static_utmp; } @@ -103,21 +99,20 @@ static struct utmp *__getutent(int utmp_fd) void endutent(void) { - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd != -1) close(static_fd); static_fd = -1; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(utmplock); } struct utmp *getutent(void) { struct utmp *ret = NULL; - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); ret = __getutent(static_fd); - UNLOCK; - + __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } @@ -127,22 +122,22 @@ static struct utmp *__getutid(const struct utmp *utmp_entry) struct utmp *lutmp; while ((lutmp = __getutent(static_fd)) != NULL) { - if ( (utmp_entry->ut_type == RUN_LVL || - utmp_entry->ut_type == BOOT_TIME || - utmp_entry->ut_type == NEW_TIME || - utmp_entry->ut_type == OLD_TIME) && - lutmp->ut_type == utmp_entry->ut_type) - { - return lutmp; - } - if ( (utmp_entry->ut_type == INIT_PROCESS || - utmp_entry->ut_type == DEAD_PROCESS || - utmp_entry->ut_type == LOGIN_PROCESS || - utmp_entry->ut_type == USER_PROCESS) && - !strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id))) - { - return lutmp; - } + if ( (utmp_entry->ut_type == RUN_LVL || + utmp_entry->ut_type == BOOT_TIME || + utmp_entry->ut_type == NEW_TIME || + utmp_entry->ut_type == OLD_TIME) && + lutmp->ut_type == utmp_entry->ut_type) + { + return lutmp; + } + if ( (utmp_entry->ut_type == INIT_PROCESS || + utmp_entry->ut_type == DEAD_PROCESS || + utmp_entry->ut_type == LOGIN_PROCESS || + utmp_entry->ut_type == USER_PROCESS) && + !strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id))) + { + return lutmp; + } } return NULL; @@ -153,10 +148,9 @@ struct utmp *getutid(const struct utmp *utmp_entry) { struct utmp *ret = NULL; - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); ret = __getutid(utmp_entry); - UNLOCK; - + __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } libc_hidden_def(getutid) @@ -165,21 +159,20 @@ struct utmp *getutline(const struct utmp *utmp_entry) { struct utmp *lutmp = NULL; - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); while ((lutmp = __getutent(static_fd)) != NULL) { if ((lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) && !strcmp(lutmp->ut_line, utmp_entry->ut_line)) { break; } } - UNLOCK; - + __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } struct utmp *pututline (const struct utmp *utmp_entry) { - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); /* Ignore the return value. That way, if they've already positioned the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); @@ -191,19 +184,19 @@ struct utmp *pututline (const struct utmp *utmp_entry) if (write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp)) utmp_entry = NULL; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(utmplock); return (struct utmp *)utmp_entry; } int utmpname (const char *new_ut_name) { - LOCK; + __UCLIBC_MUTEX_LOCK(utmplock); if (new_ut_name != NULL) { if (static_ut_name != default_file_name) free((char *)static_ut_name); static_ut_name = strdup(new_ut_name); if (static_ut_name == NULL) { - /* We should probably whine about out-of-memory + /* We should probably whine about out-of-memory * errors here... Instead just reset to the default */ static_ut_name = default_file_name; } @@ -212,6 +205,6 @@ int utmpname (const char *new_ut_name) if (static_fd != -1) close(static_fd); static_fd = -1; - UNLOCK; + __UCLIBC_MUTEX_UNLOCK(utmplock); return 0; } |