no SCCS file; new copyright; att/bsd/shared
[unix-history] / usr / src / lib / libc / stdio / snprintf.c
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)snprintf.c 5.1 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#if __STDC__
snprintf(char *str, size_t n, char const *fmt, ...)
#else
snprintf(str, n, fmt, va_alist)
char *str;
size_t n;
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
FILE f;
if ((int)n < 1)
return (EOF);
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
ret = vfprintf(&f, fmt, ap);
*f._p = 0;
va_end(ap);
return (ret);
}