diff options
Diffstat (limited to 'lib/libc/stdio')
32 files changed, 417 insertions, 34 deletions
diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index de4526e..a597b7b 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -40,10 +40,20 @@ static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #undef clearerr +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif void clearerr(fp) FILE *fp; { +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif __sclearerr(fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif } diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index 8315c3c..be92108 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -42,7 +42,12 @@ static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <stdlib.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif +int fclose(fp) register FILE *fp; { @@ -52,6 +57,9 @@ fclose(fp) errno = EBADF; return (EOF); } +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif r = fp->_flags & __SWR ? __sflush(fp) : 0; if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) r = EOF; @@ -61,7 +69,11 @@ fclose(fp) FREEUB(fp); if (HASLB(fp)) FREELB(fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif fp->_flags = 0; /* Release this FILE for reuse. */ + fp->_file = -1; fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ return (r); } diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index 4a5cf0f..fce8932 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -41,21 +41,36 @@ static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #include <errno.h> #include <stdio.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* Flush a single file, or (if fp is NULL) all files. */ +int fflush(fp) register FILE *fp; { + int retval; if (fp == NULL) return (_fwalk(__sflush)); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif if ((fp->_flags & (__SWR | __SRW)) == 0) { errno = EBADF; - return (EOF); + retval = EOF; + } else { + retval = __sflush(fp); } - return (__sflush(fp)); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } +int __sflush(fp) register FILE *fp; { diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 800846c..7e2738f 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -39,9 +39,22 @@ static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif +int fgetc(fp) FILE *fp; { - return (__sgetc(fp)); + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = __sgetc(fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c index 1f4ec1d..4ac0be4 100644 --- a/lib/libc/stdio/fgetpos.c +++ b/lib/libc/stdio/fgetpos.c @@ -39,10 +39,23 @@ static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif +int fgetpos(fp, pos) FILE *fp; fpos_t *pos; { - return((*pos = ftell(fp)) == (fpos_t)-1); + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = (*pos = ftell(fp)) == (fpos_t)-1; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return(retval); } diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index 09f6877..c478267 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -40,6 +40,11 @@ static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; #include <stdio.h> #include <string.h> +#include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * Read at most n-1 characters from the given file. @@ -59,6 +64,9 @@ fgets(buf, n, fp) if (n == 0) /* sanity check */ return (NULL); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif s = buf; n--; /* leave space for NUL */ while (n != 0) { @@ -68,8 +76,12 @@ fgets(buf, n, fp) if ((len = fp->_r) <= 0) { if (__srefill(fp)) { /* EOF/error: stop with partial or no line */ - if (s == buf) + if (s == buf) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (NULL); + } break; } len = fp->_r; @@ -91,6 +103,9 @@ fgets(buf, n, fp) fp->_p = t; (void)memcpy((void *)s, (void *)p, len); s[len] = 0; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (buf); } fp->_r -= len; @@ -100,5 +115,8 @@ fgets(buf, n, fp) n -= len; } *s = 0; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (buf); } diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c index 3bee513..7cf54ff 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -42,6 +42,10 @@ static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <stdlib.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * fpurge: like fflush, but without writing anything: leave the @@ -51,15 +55,23 @@ int fpurge(fp) register FILE *fp; { + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif if (!fp->_flags) { errno = EBADF; - return(EOF); + retval = EOF; + } else { + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + retval = 0; } - - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; - return (0); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index c86f711..09b55d5 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -39,10 +39,23 @@ static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif +int fputc(c, fp) int c; register FILE *fp; { - return (putc(c, fp)); + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = putc(c, fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 9f9be2e..92fcc30 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -41,14 +41,20 @@ static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <string.h> #include "fvwrite.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * Write the given string to the given file. */ +int fputs(s, fp) const char *s; FILE *fp; { + int retval; struct __suio uio; struct __siov iov; @@ -56,5 +62,12 @@ fputs(s, fp) iov.iov_len = uio.uio_resid = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; - return (__sfvwrite(fp, &uio)); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = __sfvwrite(fp, &uio); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index 22436ec..7132e85 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -40,6 +40,11 @@ static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #include <stdio.h> #include <string.h> +#include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif size_t fread(buf, size, count, fp) @@ -59,6 +64,9 @@ fread(buf, size, count, fp) */ if ((resid = count * size) == 0) return (0); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif if (fp->_r < 0) fp->_r = 0; total = resid; @@ -77,5 +85,8 @@ fread(buf, size, count, fp) (void)memcpy((void *)p, (void *)fp->_p, resid); fp->_r -= resid; fp->_p += resid; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (count); } diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c index f0e726a..bbb3155 100644 --- a/lib/libc/stdio/fscanf.c +++ b/lib/libc/stdio/fscanf.c @@ -44,14 +44,20 @@ static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93"; #else #include <varargs.h> #endif +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif #if __STDC__ +int fscanf(FILE *fp, char const *fmt, ...) { int ret; va_list ap; va_start(ap, fmt); #else +int fscanf(fp, fmt, va_alist) FILE *fp; char *fmt; @@ -62,7 +68,13 @@ fscanf(fp, fmt, va_alist) va_start(ap); #endif +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif ret = __svfscanf(fp, fmt, ap); va_end(ap); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (ret); } diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 9cb04ad..1e99de9 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -45,6 +45,10 @@ static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; #include <stdlib.h> #include <errno.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif #define POS_ERR (-(fpos_t)1) @@ -68,6 +72,9 @@ fseek(fp, offset, whence) if (!__sdidinit) __sinit(); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif /* * Have to be able to seek. */ @@ -92,8 +99,12 @@ fseek(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1L) + if (curoff == -1L) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); + } } if (fp->_flags & __SRD) { curoff -= fp->_r; @@ -115,6 +126,9 @@ fseek(fp, offset, whence) default: errno = EINVAL; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); } @@ -198,6 +212,9 @@ fseek(fp, offset, whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (0); } @@ -224,6 +241,9 @@ fseek(fp, offset, whence) fp->_p += n; fp->_r -= n; } +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (0); /* @@ -233,6 +253,9 @@ fseek(fp, offset, whence) dumb: if (__sflush(fp) || (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); } /* success: clear EOF indicator and discard ungetc() data */ @@ -242,5 +265,8 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (0); } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 724e543..271490a 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -41,6 +41,10 @@ static char sccsid[] = "@(#)ftell.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <errno.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * ftell: return current offset. @@ -56,6 +60,9 @@ ftell(fp) return (-1L); } +#ifdef _THREAD_SAFE + _thread_flockfile((FILE *) fp,__FILE__,__LINE__); +#endif /* * Find offset of underlying I/O object, then * adjust for buffered bytes. @@ -64,8 +71,12 @@ ftell(fp) pos = fp->_offset; else { pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1L) + if (pos == -1L) { +#ifdef _THREAD_SAFE + _thread_funlockfile((FILE *) fp); +#endif return (pos); + } } if (fp->_flags & __SRD) { /* @@ -84,5 +95,8 @@ ftell(fp) */ pos += fp->_p - fp->_bf._base; } +#ifdef _THREAD_SAFE + _thread_funlockfile((FILE *) fp); +#endif return (pos); } diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index dbc2e97..7efb0ac 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -41,6 +41,10 @@ static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include "local.h" #include "fvwrite.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * Write `count' objects (each size `size') from memory to the given file. @@ -61,12 +65,18 @@ fwrite(buf, size, count, fp) uio.uio_iov = &iov; uio.uio_iovcnt = 1; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif /* * The usual case is success (__sfvwrite returns 0); * skip the divide if this happens, since divides are * generally slow and since this occurs whenever size==0. */ - if (__sfvwrite(fp, &uio) == 0) - return (count); - return ((n - uio.uio_resid) / size); + if (__sfvwrite(fp, &uio) != 0) + count = (n - uio.uio_resid) / size; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (count); } diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index 1e900cd..c0726ee 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -39,14 +39,27 @@ static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * A subroutine version of the macro getc. */ #undef getc +int getc(fp) register FILE *fp; { - return (__sgetc(fp)); + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = __sgetc(fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index 20e52b7..7aeef8a 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -42,10 +42,23 @@ static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; * A subroutine version of the macro getchar. */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif #undef getchar +int getchar() { - return (getc(stdin)); + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(stdin,__FILE__,__LINE__); +#endif + retval = getc(stdin); +#ifdef _THREAD_SAFE + _thread_funlockfile(stdin); +#endif + return (retval); } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index c18353b..f1d42b1 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -39,15 +39,28 @@ static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * A subroutine version of the macro putc. */ #undef putc +int putc(c, fp) int c; register FILE *fp; { - return (__sputc(c, fp)); + int retval; +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = __sputc(c, fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index 036b897..5e04a6c 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -39,16 +39,29 @@ static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif #undef putchar /* * A subroutine version of the macro putchar */ +int putchar(c) int c; { + int retval; register FILE *so = stdout; - return (__sputc(c, so)); +#ifdef _THREAD_SAFE + _thread_flockfile(so,__FILE__,__LINE__); +#endif + retval = __sputc(c, so); +#ifdef _THREAD_SAFE + _thread_funlockfile(so); +#endif + return (retval); } diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c index 96a8184..e8a35c5 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -41,13 +41,19 @@ static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <string.h> #include "fvwrite.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * Write the given string to stdout, appending a newline. */ +int puts(s) char const *s; { + int retval; size_t c = strlen(s); struct __suio uio; struct __siov iov[2]; @@ -59,5 +65,12 @@ puts(s) uio.uio_resid = c + 1; uio.uio_iov = &iov[0]; uio.uio_iovcnt = 2; - return (__sfvwrite(stdout, &uio) ? EOF : '\n'); +#ifdef _THREAD_SAFE + _thread_flockfile(stdout,__FILE__,__LINE__); +#endif + retval = __sfvwrite(stdout, &uio) ? EOF : '\n'; +#ifdef _THREAD_SAFE + _thread_funlockfile(stdout); +#endif + return (retval); } diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c index 4ba8982..604bed0 100644 --- a/lib/libc/stdio/putw.c +++ b/lib/libc/stdio/putw.c @@ -40,11 +40,17 @@ static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include "fvwrite.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif +int putw(w, fp) int w; FILE *fp; { + int retval; struct __suio uio; struct __siov iov; @@ -52,5 +58,12 @@ putw(w, fp) iov.iov_len = uio.uio_resid = sizeof(w); uio.uio_iov = &iov; uio.uio_iovcnt = 1; - return (__sfvwrite(fp, &uio)); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif + retval = __sfvwrite(fp, &uio); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (retval); } diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index 4f8391b..f20f619 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -40,12 +40,22 @@ static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93"; #include <errno.h> #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif void rewind(fp) register FILE *fp; { +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif (void) fseek(fp, 0L, SEEK_SET); clearerr(fp); +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif errno = 0; /* not required, but seems reasonable */ } diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c index d36b13a..5faf018 100644 --- a/lib/libc/stdio/scanf.c +++ b/lib/libc/stdio/scanf.c @@ -44,10 +44,16 @@ static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93"; #else #include <varargs.h> #endif +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif #if __STDC__ +int scanf(char const *fmt, ...) #else +int scanf(fmt, va_alist) char *fmt; va_dcl @@ -61,7 +67,13 @@ scanf(fmt, va_alist) #else va_start(ap); #endif +#ifdef _THREAD_SAFE + _thread_flockfile(stdin,__FILE__,__LINE__); +#endif ret = __svfscanf(stdin, fmt, ap); va_end(ap); +#ifdef _THREAD_SAFE + _thread_funlockfile(stdin); +#endif return (ret); } diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 867f9b4..c6c037d 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -41,11 +41,16 @@ static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; #include <stdio.h> #include <stdlib.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * Set one of the three kinds of buffering, optionally including * a buffer. */ +int setvbuf(fp, buf, mode, size) register FILE *fp; char *buf; @@ -65,6 +70,9 @@ setvbuf(fp, buf, mode, size) if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) return (EOF); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif /* * Write current buffer, if any. Discard unread input (including * ungetc data), cancel line buffering, and free old buffer if @@ -116,6 +124,9 @@ nbf: fp->_w = 0; fp->_bf._base = fp->_p = fp->_nbuf; fp->_bf._size = 1; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (ret); } flags |= __SMBF; @@ -156,5 +167,8 @@ nbf: } __cleanup = _cleanup; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (ret); } diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index 3c3cf7d..82fad1a 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -46,8 +46,10 @@ static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; #endif #if __STDC__ +int snprintf(char *str, size_t n, char const *fmt, ...) #else +int snprintf(str, n, fmt, va_alist) char *str; size_t n; @@ -66,6 +68,7 @@ snprintf(str, n, fmt, va_alist) #else va_start(ap); #endif + f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n - 1; diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c index 254064f..e71f7d0 100644 --- a/lib/libc/stdio/sprintf.c +++ b/lib/libc/stdio/sprintf.c @@ -48,8 +48,10 @@ static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93"; #include "local.h" #if __STDC__ +int sprintf(char *str, char const *fmt, ...) #else +int sprintf(str, fmt, va_alist) char *str; char *fmt; @@ -60,6 +62,7 @@ sprintf(str, fmt, va_alist) va_list ap; FILE f; + f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = INT_MAX; diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c index bb72744..dc96312 100644 --- a/lib/libc/stdio/sscanf.c +++ b/lib/libc/stdio/sscanf.c @@ -59,8 +59,10 @@ eofread(cookie, buf, len) } #if __STDC__ +int sscanf(const char *str, char const *fmt, ...) #else +int sscanf(str, fmt, va_alist) char *str; char *fmt; @@ -71,6 +73,7 @@ sscanf(str, fmt, va_alist) va_list ap; FILE f; + f._file = -1; f._flags = __SRD; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._r = strlen(str); diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c index deaed75..25f59d7 100644 --- a/lib/libc/stdio/ungetc.c +++ b/lib/libc/stdio/ungetc.c @@ -42,6 +42,10 @@ static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; #include <stdlib.h> #include <string.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * Expand the ungetc buffer `in place'. That is, adjust fp->_p when @@ -49,7 +53,7 @@ static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; * and move the bytes in the buffer around as necessary so that they * are all at the end (stack-style). */ -static +static int __submore(fp) register FILE *fp; { @@ -82,6 +86,7 @@ __submore(fp) return (0); } +int ungetc(c, fp) int c; register FILE *fp; @@ -90,16 +95,27 @@ ungetc(c, fp) return (EOF); if (!__sdidinit) __sinit(); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif if ((fp->_flags & __SRD) == 0) { /* * Not already reading: no good unless reading-and-writing. * Otherwise, flush any current write stuff. */ - if ((fp->_flags & __SRW) == 0) + if ((fp->_flags & __SRW) == 0) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); + } if (fp->_flags & __SWR) { - if (__sflush(fp)) + if (__sflush(fp)) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); + } fp->_flags &= ~__SWR; fp->_w = 0; fp->_lbfsize = 0; @@ -113,10 +129,17 @@ ungetc(c, fp) * This may require expanding the current ungetc buffer. */ if (HASUB(fp)) { - if (fp->_r >= fp->_ub._size && __submore(fp)) + if (fp->_r >= fp->_ub._size && __submore(fp)) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); + } *--fp->_p = c; fp->_r++; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (c); } fp->_flags &= ~__SEOF; @@ -130,6 +153,9 @@ ungetc(c, fp) fp->_p[-1] == c) { fp->_p--; fp->_r++; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (c); } @@ -144,5 +170,8 @@ ungetc(c, fp) fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; fp->_r = 1; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (c); } diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index f53db61..3c3d4d3 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -59,6 +59,10 @@ static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; #include "local.h" #include "fvwrite.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* Define FLOATING_POINT to get floating point. */ #define FLOATING_POINT @@ -366,14 +370,25 @@ vfprintf(fp, fmt0, ap) flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \ (u_long)va_arg(ap, u_int)) +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (cantwrite(fp)) + if (cantwrite(fp)) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); + } /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && - fp->_file >= 0) + fp->_file >= 0) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (__sbprintf(fp, fmt0, ap)); + } fmt = (char *)fmt0; uio.uio_iov = iovp = iov; @@ -782,7 +797,12 @@ number: if ((dprec = prec) >= 0) done: FLUSH(); error: - return (__sferror(fp) ? EOF : ret); + if (__sferror(fp)) + ret = EOF; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif + return (ret); /* NOTREACHED */ } diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c index 5d12865..677039e 100644 --- a/lib/libc/stdio/vscanf.c +++ b/lib/libc/stdio/vscanf.c @@ -39,11 +39,24 @@ static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif +int vscanf(fmt, ap) const char *fmt; _BSD_VA_LIST_ ap; { + int retval; - return (__svfscanf(stdin, fmt, ap)); +#ifdef _THREAD_SAFE + _thread_flockfile(stdin,__FILE__,__LINE__); +#endif + retval = __svfscanf(stdin, fmt, ap); +#ifdef _THREAD_SAFE + _thread_funlockfile(stdin); +#endif + return (retval); } diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index ccc8af6..1bff18b 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> +int vsnprintf(str, n, fmt, ap) char *str; size_t n; @@ -51,6 +52,7 @@ vsnprintf(str, n, fmt, ap) if ((int)n < 1) return (EOF); + f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n - 1; diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index c6e192a..cdfb9eb 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -41,6 +41,7 @@ static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <limits.h> +int vsprintf(str, fmt, ap) char *str; const char *fmt; @@ -49,6 +50,7 @@ vsprintf(str, fmt, ap) int ret; FILE f; + f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = INT_MAX; diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c index e776689..0d4d05a 100644 --- a/lib/libc/stdio/vsscanf.c +++ b/lib/libc/stdio/vsscanf.c @@ -52,6 +52,7 @@ eofread(cookie, buf, len) return (0); } +int vsscanf(str, fmt, ap) const char *str; const char *fmt; @@ -59,6 +60,7 @@ vsscanf(str, fmt, ap) { FILE f; + f._file = -1; f._flags = __SRD; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._r = strlen(str); |