summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/vfprintf.c
diff options
context:
space:
mode:
authorJordan K. Hubbard <jkh@FreeBSD.org>1996-06-03 05:12:29 +0000
committerJordan K. Hubbard <jkh@FreeBSD.org>1996-06-03 05:12:29 +0000
commitaccd7f182e87d2a1d578214211ee7ded32753803 (patch)
tree90de65019704d8a469505b67d00c11e813d480e0 /lib/libc/stdio/vfprintf.c
parentc3287ad65e82f73d993c7537d1fc5a7a16199449 (diff)
Notes
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
-rw-r--r--lib/libc/stdio/vfprintf.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index f53db612ff60..0f241deebe10 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
@@ -302,8 +306,7 @@ vfprintf(fp, fmt0, ap)
u_quad_t uqval; /* %q integers */
int base; /* base for [diouxX] conversion */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
- int fieldsz; /* field size expanded by sign, etc */
- int realsz; /* field size expanded by dprec */
+ int realsz; /* field size expanded by dprec, sign, etc */
int size; /* size of converted field or string */
char *xdigs; /* digits for [xX] conversion */
#define NIOV 8
@@ -366,14 +369,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;
@@ -693,14 +707,13 @@ number: if ((dprec = prec) >= 0)
* floating precision; finally, if LADJUST, pad with blanks.
*
* Compute actual size, so we know how much to pad.
- * fieldsz excludes decimal prec; realsz includes it.
+ * size excludes decimal prec; realsz includes it.
*/
- fieldsz = size;
+ realsz = dprec > size ? dprec : size;
if (sign)
- fieldsz++;
+ realsz++;
else if (flags & HEXPREFIX)
- fieldsz += 2;
- realsz = dprec > fieldsz ? dprec : fieldsz;
+ realsz += 2;
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0)
@@ -720,7 +733,7 @@ number: if ((dprec = prec) >= 0)
PAD(width - realsz, zeroes);
/* leading zeroes from decimal precision */
- PAD(dprec - fieldsz, zeroes);
+ PAD(dprec - size, zeroes);
/* the string or number proper */
#ifdef FLOATING_POINT
@@ -782,7 +795,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 */
}