diff options
| author | Andrey A. Chernov <ache@FreeBSD.org> | 1997-12-24 23:02:47 +0000 |
|---|---|---|
| committer | Andrey A. Chernov <ache@FreeBSD.org> | 1997-12-24 23:02:47 +0000 |
| commit | 6e690ad4ca3f240aa8deb1a18660c97c72e6d2c3 (patch) | |
| tree | e4eb87a006e6435936a4d1fb84a91528af395108 /lib/libc/stdio/vsnprintf.c | |
| parent | e0b123f6d0eca4574a0d93f3e4f1f0d2aa93b4c4 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdio/vsnprintf.c')
| -rw-r--r-- | lib/libc/stdio/vsnprintf.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 738dd212f318..fa91175e92f1 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: vsnprintf.c,v 1.7 1997/12/24 14:32:40 ache Exp $"; + "$Id: vsnprintf.c,v 1.8 1997/12/24 20:24:08 ache Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -54,16 +54,19 @@ vsnprintf(str, n, fmt, ap) { int ret; FILE f; + int on; - if (n == 0) - return (0); - if (--n > INT_MAX) + on = n; + if (n > 0) + n--; + if (n > INT_MAX) return (EOF); f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n; ret = vfprintf(&f, fmt, ap); - *f._p = 0; - return (ret > (int)n ? n : ret); + if (on > 0) + *f._p = '\0'; + return (ret); } |
