From 619b731f5bb5e09dcf1eaf1fbd96383ca64398fd Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 22 Jan 1996 00:02:33 +0000 Subject: Reviewed by: julian and (hsu?) Submitted by: John Birrel(L?) changes for threadsafe operations --- lib/libc/stdio/vfprintf.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib/libc/stdio/vfprintf.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 +#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 */ } -- cgit v1.1