summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/snprintf.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1997-12-24 23:02:47 +0000
committerache <ache@FreeBSD.org>1997-12-24 23:02:47 +0000
commitd6bcc605a0dda1fae5485a69235f91b7eaa17666 (patch)
treef4c404b45a764f364d855cd1dc1c90f8a1eec66c /lib/libc/stdio/snprintf.c
parent7bbce1048f6b1d616d9d1a7a290a7e91f36e5e8b (diff)
downloadFreeBSD-src-d6bcc605a0dda1fae5485a69235f91b7eaa17666.zip
FreeBSD-src-d6bcc605a0dda1fae5485a69235f91b7eaa17666.tar.gz
Return back to BSD snprintf semantics which recent C9x standard adopts
instead of Singe Unix, thanx Bruce for explaining, I am not realize standards war was there. But now, fix n == 0 case to not return error and fix check for too big n. Things left to do: check for overflow in arguments.
Diffstat (limited to 'lib/libc/stdio/snprintf.c')
-rw-r--r--lib/libc/stdio/snprintf.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c
index bfcf72c..b3944e3 100644
--- a/lib/libc/stdio/snprintf.c
+++ b/lib/libc/stdio/snprintf.c
@@ -39,7 +39,7 @@
static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
- "$Id: snprintf.c,v 1.7 1997/12/24 14:32:39 ache Exp $";
+ "$Id: snprintf.c,v 1.8 1997/12/24 20:24:05 ache Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -65,10 +65,12 @@ snprintf(str, n, fmt, va_alist)
int ret;
va_list ap;
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);
#if __STDC__
va_start(ap, fmt);
@@ -80,7 +82,8 @@ snprintf(str, n, fmt, va_alist)
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
ret = vfprintf(&f, fmt, ap);
- *f._p = 0;
+ if (on > 0)
+ *f._p = '\0';
va_end(ap);
- return (ret > (int)n ? n : ret);
+ return (ret);
}
OpenPOWER on IntegriCloud