diff options
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/ferror.3 | 2 | ||||
| -rw-r--r-- | lib/libc/stdio/fgets.3 | 2 | ||||
| -rw-r--r-- | lib/libc/stdio/setvbuf.c | 5 | ||||
| -rw-r--r-- | lib/libc/stdio/stdio.3 | 2 | ||||
| -rw-r--r-- | lib/libc/stdio/strerror.3 | 4 | ||||
| -rw-r--r-- | lib/libc/stdio/tempnam.c | 22 | ||||
| -rw-r--r-- | lib/libc/stdio/vfprintf.c | 58 |
7 files changed, 63 insertions, 32 deletions
diff --git a/lib/libc/stdio/ferror.3 b/lib/libc/stdio/ferror.3 index e90af8fc7167..a4e367835201 100644 --- a/lib/libc/stdio/ferror.3 +++ b/lib/libc/stdio/ferror.3 @@ -82,7 +82,7 @@ The function .Fn fileno examines the argument .Fa stream -and returns its integer desciptor. +and returns its integer descriptor. .Sh ERRORS These functions should not fail and do not set the external variable diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3 index 8676aee498ab..89a5cdbe8c62 100644 --- a/lib/libc/stdio/fgets.3 +++ b/lib/libc/stdio/fgets.3 @@ -93,8 +93,8 @@ they return The .Fn fgets and -functions .Fn gets +functions do not distinguish between end-of-file and error, and callers must use .Xr feof 3 and diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 1928ae14160b..78e616387269 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -137,11 +137,14 @@ nbf: flags |= __SLBF; if (flags & __SRW) flags &= ~(__SRD | __SWR); - fp->_w = 0; fp->_flags = flags; fp->_bf._base = fp->_p = (unsigned char *)buf; fp->_bf._size = size; fp->_lbfsize = 0; + if (flags & __SWR) + __swsetup(fp); + else + fp->_w = 0; __cleanup = _cleanup; return (ret); diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3 index 60fcb2e57173..98143dc62928 100644 --- a/lib/libc/stdio/stdio.3 +++ b/lib/libc/stdio/stdio.3 @@ -77,7 +77,7 @@ function. A file is disassociated from a stream by .Em closing the file. -Ouput streams are flushed (any unwritten buffer contents are transfered +Ouput streams are flushed (any unwritten buffer contents are transferred to the host environment) before the stream is disassociated from the file. The value of a pointer to a .Dv FILE diff --git a/lib/libc/stdio/strerror.3 b/lib/libc/stdio/strerror.3 index 3f590e5d35b2..7989ea798e7d 100644 --- a/lib/libc/stdio/strerror.3 +++ b/lib/libc/stdio/strerror.3 @@ -47,7 +47,7 @@ .Sh SYNOPSIS .Vt extern int errno; .Vt extern char *sys_errlist[]; -.Fd #include <stdio.h> +.Fd #include <string.h> .Ft void .Fn perror "const char *string" .Ft char * @@ -61,7 +61,7 @@ functions lookup the error message string affiliated with an error number. .Pp The -.Fn sterror +.Fn strerror function accepts an error number argument .Fa errnum and diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c index 988763aac5b8..e3ee6c072f05 100644 --- a/lib/libc/stdio/tempnam.c +++ b/lib/libc/stdio/tempnam.c @@ -48,6 +48,8 @@ tempnam(dir, pfx) { int sverrno; char *f, *name; + static char unique[] = "@AA"; + int idx; if (!(name = malloc(MAXPATHLEN))) return(NULL); @@ -55,27 +57,35 @@ tempnam(dir, pfx) if (!pfx) pfx = "tmp."; + /* Bump up the unique counter. The following is also a gross abuse + * of C, but I don't really care. This whole function is superceeded + * by mkstemp() anyway. + */ + idx = unique[0] < 'Z' ? 0 : unique[1] < 'Z' ? 1 : unique[2] < 'Z' ? + 2 : (int)strcpy(unique, "AAA"), 0; + ++unique[idx]; + if (f = getenv("TMPDIR")) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); + (void)snprintf(name, MAXPATHLEN, "%s%s%s%sXXXXXX", f, + *(f + strlen(f) - 1) == '/'? "": "/", pfx, unique); if (f = mktemp(name)) return(f); } if (f = (char *)dir) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); + (void)snprintf(name, MAXPATHLEN, "%s%s%s%sXXXXXX", f, + *(f + strlen(f) - 1) == '/'? "": "/", pfx, unique); if (f = mktemp(name)) return(f); } f = P_tmpdir; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, pfx, unique); if (f = mktemp(name)) return(f); f = _PATH_TMP; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, pfx, unique); if (f = mktemp(name)) return(f); diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 8d064c696c2e..dea8a5620da6 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -35,7 +35,8 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)vfprintf.c 5.50 (Berkeley) 12/16/92"; +/*static char *sccsid = "from: @(#)vfprintf.c 5.50 (Berkeley) 12/16/92";*/ +static char *rcsid = "$Id: vfprintf.c,v 1.5 1994/02/06 07:35:02 wollman Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -120,6 +121,7 @@ __sbprintf(fp, fmt, ap) #ifdef FLOATING_POINT +#include <locale.h> #include <math.h> #include "floatio.h" @@ -159,7 +161,7 @@ int vfprintf(fp, fmt0, ap) FILE *fp; const char *fmt0; - va_list ap; + _VA_LIST_ ap; { register char *fmt; /* format string */ register int ch; /* character from fmt */ @@ -382,20 +384,23 @@ reswitch: switch (ch) { base = DEC; goto number; #ifdef FLOATING_POINT - case 'e': /* anomalous precision */ + case 'e': case 'E': - prec = (prec == -1) ? - DEFPREC + 1 : prec + 1; - /* FALLTHROUGH */ - goto fp_begin; - case 'f': /* always print trailing zeroes */ - if (prec != 0) - flags |= ALT; + case 'f': case 'g': case 'G': - if (prec == -1) + if (prec == -1) { prec = DEFPREC; -fp_begin: _double = va_arg(ap, double); + } else if ((ch == 'g' || ch == 'G') && prec == 0) { + prec = 1; + } + + if (flags & LONGDBL) { + _double = (double) va_arg(ap, long double); + } else { + _double = va_arg(ap, double); + } + /* do this before tricky precision changes */ if (isinf(_double)) { if (_double < 0) @@ -409,6 +414,7 @@ fp_begin: _double = va_arg(ap, double); size = 3; break; } + flags |= FPT; cp = cvt(_double, prec, flags, &softsign, &expt, ch, &ndig); @@ -469,7 +475,12 @@ fp_begin: _double = va_arg(ap, double); * -- ANSI X3J11 */ /* NOSTRICT */ + /* no easy way to tell in cpp how big a type is */ +#if defined(__i386) + _uquad = (u_quad_t)(u_long)va_arg(ap, void *); +#else _uquad = (u_quad_t)va_arg(ap, void *); +#endif base = HEX; xdigs = "0123456789abcdef"; flags |= HEXPREFIX; @@ -631,9 +642,8 @@ number: if ((dprec = prec) >= 0) } else { /* glue together f_p fragments */ if (ch >= 'f') { /* 'f' or 'g' */ if (_double == 0) { - /* kludge for __dtoa irregularity */ - if (prec == 0 || - (flags & ALT) == 0) { + /* kludge for __dtoa irregularity */ + if (expt >= ndig && (flags & ALT) == 0) { PRINT("0", 1); } else { PRINT("0.", 2); @@ -701,18 +711,26 @@ cvt(value, ndigits, flags, sign, decpt, ch, length) int mode, dsgn; char *digits, *bp, *rve; - if (ch == 'f') - mode = 3; - else { - mode = 2; + if (ch == 'f') { + mode = 3; /* ndigits after the decimal point */ + } else { + /* To obtain ndigits after the decimal point for the 'e' + * and 'E' formats, round to ndigits + 1 significant + * figures. + */ + if (ch == 'e' || ch == 'E') { + ndigits++; + } + mode = 2; /* ndigits significant digits */ } + if (value < 0) { value = -value; *sign = '-'; } else *sign = '\000'; digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve); - if (flags & ALT) { /* Print trailing zeros */ + if ((ch != 'g' && ch != 'G') || flags & ALT) { /* Print trailing zeros */ bp = digits + ndigits; if (ch == 'f') { if (*digits == '0' && value) |
