From a4a741f7cfab4f58efbc70e19b70b498c81b0748 Mon Sep 17 00:00:00 2001 From: millert Date: Mon, 12 Jan 1998 06:14:30 +0000 Subject: Based on some FreeBSD changes: For *s*printf, set f._file to -1 like the comments in stdio.h say. Use '\0', not 0, where appropriate. Don't error out on size of '0' for v?snprintf(). --- lib/libc/stdio/snprintf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/libc/stdio/snprintf.c') diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index 2afabe725a0..9523431bf00 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -35,9 +35,10 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: snprintf.c,v 1.4 1997/11/29 19:28:29 millert Exp $"; +static char rcsid[] = "$OpenBSD: snprintf.c,v 1.5 1998/01/12 06:14:31 millert Exp $"; #endif /* LIBC_SCCS and not lint */ +#include #include #ifdef __STDC__ #include @@ -60,18 +61,21 @@ snprintf(str, n, fmt, va_alist) va_list ap; FILE f; - if ((int)n < 1) - return (-1); + /* While snprintf(3) specifies size_t stdio uses an int internally */ + if (n > INT_MAX) + n = INT_MAX; #ifdef __STDC__ va_start(ap, fmt); #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; + f._bf._size = f._w = n ? n - 1 : 0; ret = vfprintf(&f, fmt, ap); - *f._p = 0; + if (n) + *f._p = 0; va_end(ap); return (ret); } -- cgit v1.2.3-59-g8ed1b