xref: /netbsd-src/lib/libc/stdio/snprintf_ss.c (revision aa781c37c2b88f8533a2c5cbe8c41ae637b02400)
1*aa781c37Schristos /*	$NetBSD: snprintf_ss.c,v 1.4 2007/02/02 23:00:28 christos Exp $	*/
2abca035cSchristos 
3abca035cSchristos /*-
4abca035cSchristos  * Copyright (c) 1990, 1993
5abca035cSchristos  *	The Regents of the University of California.  All rights reserved.
6abca035cSchristos  *
7abca035cSchristos  * This code is derived from software contributed to Berkeley by
8abca035cSchristos  * Chris Torek.
9abca035cSchristos  *
10abca035cSchristos  * Redistribution and use in source and binary forms, with or without
11abca035cSchristos  * modification, are permitted provided that the following conditions
12abca035cSchristos  * are met:
13abca035cSchristos  * 1. Redistributions of source code must retain the above copyright
14abca035cSchristos  *    notice, this list of conditions and the following disclaimer.
15abca035cSchristos  * 2. Redistributions in binary form must reproduce the above copyright
16abca035cSchristos  *    notice, this list of conditions and the following disclaimer in the
17abca035cSchristos  *    documentation and/or other materials provided with the distribution.
18abca035cSchristos  * 3. Neither the name of the University nor the names of its contributors
19abca035cSchristos  *    may be used to endorse or promote products derived from this software
20abca035cSchristos  *    without specific prior written permission.
21abca035cSchristos  *
22abca035cSchristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23abca035cSchristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24abca035cSchristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25abca035cSchristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26abca035cSchristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27abca035cSchristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28abca035cSchristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29abca035cSchristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30abca035cSchristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31abca035cSchristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32abca035cSchristos  * SUCH DAMAGE.
33abca035cSchristos  */
34abca035cSchristos 
35abca035cSchristos #include <sys/cdefs.h>
36abca035cSchristos #if defined(LIBC_SCCS) && !defined(lint)
37abca035cSchristos #if 0
38abca035cSchristos static char sccsid[] = "@(#)snprintf.c	8.1 (Berkeley) 6/4/93";
39abca035cSchristos #else
40*aa781c37Schristos __RCSID("$NetBSD: snprintf_ss.c,v 1.4 2007/02/02 23:00:28 christos Exp $");
41abca035cSchristos #endif
42abca035cSchristos #endif /* LIBC_SCCS and not lint */
43abca035cSchristos 
44abca035cSchristos #include "namespace.h"
45abca035cSchristos 
46abca035cSchristos #include <assert.h>
47abca035cSchristos #include <errno.h>
48abca035cSchristos #include <stdarg.h>
49abca035cSchristos #include <stdio.h>
50abca035cSchristos 
51abca035cSchristos #include "reentrant.h"
524ca73ce8Schristos #include "extern.h"
53abca035cSchristos #include "local.h"
54abca035cSchristos 
55abca035cSchristos #ifdef __weak_alias
__weak_alias(snprintf_ss,_snprintf_ss)569984f754Schristos __weak_alias(snprintf_ss,_snprintf_ss)
57abca035cSchristos #endif
58abca035cSchristos 
59abca035cSchristos int
60abca035cSchristos snprintf_ss(char *str, size_t n, char const *fmt, ...)
61abca035cSchristos {
62abca035cSchristos 	va_list ap;
63*aa781c37Schristos 	int ret;
64abca035cSchristos 
65abca035cSchristos 	va_start(ap, fmt);
66*aa781c37Schristos 	ret = vsnprintf_ss(str, n, fmt, ap);
67abca035cSchristos 	va_end(ap);
68*aa781c37Schristos 	return ret;
69abca035cSchristos }
70