1 /* @(#)jssprintf.c	1.19 17/08/03 Copyright 1985, 1995-2017 J. Schilling */
2 /*
3  *	Copyright (c) 1985, 1995-2017 J. Schilling
4  */
5 /*
6  * The contents of this file are subject to the terms of the
7  * Common Development and Distribution License, Version 1.0 only
8  * (the "License").  You may not use this file except in compliance
9  * with the License.
10  *
11  * See the file CDDL.Schily.txt in this distribution for details.
12  * A copy of the CDDL is also available via the Internet at
13  * http://www.opensource.org/licenses/cddl1.txt
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file CDDL.Schily.txt from this distribution.
17  */
18 
19 #include <schily/mconfig.h>
20 #include <schily/varargs.h>
21 #include <schily/standard.h>
22 #include <schily/schily.h>
23 
24 /*
25  * Do not include stdio.h, BSD systems define sprintf the wrong way!
26  */
27 EXPORT	int js_sprintf __PR((char *, const char *, ...));
28 
29 #ifdef	PROTOTYPES
30 static void
_cput(char c,void * ba)31 _cput(char c, void *ba)
32 #else
33 static void
34 _cput(c, ba)
35 	char	c;
36 	void	*ba;
37 #endif
38 {
39 	*(*(char **)ba)++ = c;
40 }
41 
42 /* VARARGS2 */
43 #ifdef	PROTOTYPES
44 EXPORT int
js_sprintf(char * buf,const char * form,...)45 js_sprintf(char *buf, const char *form, ...)
46 #else
47 EXPORT int
48 js_sprintf(buf, form, va_alist)
49 	char	*buf;
50 	char	*form;
51 	va_dcl
52 #endif
53 {
54 	va_list	args;
55 	int	cnt;
56 	char	*bp = buf;
57 
58 #ifdef	PROTOTYPES
59 	va_start(args, form);
60 #else
61 	va_start(args);
62 #endif
63 	cnt = format(_cput, &bp, form,  args);
64 	va_end(args);
65 	*bp = '\0';
66 
67 	return (cnt);
68 }
69