1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * and/or other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 /*
19 FUNCTION
20 <<siprintf>>, <<fiprintf>>, <<iprintf>>, <<sniprintf>>, <<asiprintf>>, <<asniprintf>>---format output (integer only)
21 
22 INDEX
23 	fiprintf
24 INDEX
25 	_fiprintf_r
26 INDEX
27 	iprintf
28 INDEX
29 	_iprintf_r
30 INDEX
31 	siprintf
32 INDEX
33 	_siprintf_r
34 INDEX
35 	sniprintf
36 INDEX
37 	_sniprintf_r
38 INDEX
39 	asiprintf
40 INDEX
41 	_asiprintf_r
42 INDEX
43 	asniprintf
44 INDEX
45 	_asniprintf_r
46 
47 SYNOPSIS
48         #include <stdio.h>
49 
50         int iprintf(const char *<[format]>, ...);
51         int fiprintf(FILE *<[fd]>, const char *<[format]> , ...);
52         int siprintf(char *<[str]>, const char *<[format]>, ...);
53         int sniprintf(char *<[str]>, size_t <[size]>, const char *<[format]>,
54 			...);
55         int asiprintf(char **<[strp]>, const char *<[format]>, ...);
56         char *asniprintf(char *<[str]>, size_t *<[size]>,
57 			const char *<[format]>, ...);
58 
59         int iprintf( const char *<[format]>, ...);
60         int fiprintf( FILE *<[fd]>,
61                         const char *<[format]>, ...);
62         int siprintf( char *<[str]>,
63                         const char *<[format]>, ...);
64         int sniprintf( char *<[str]>, size_t <[size]>,
65                          const char *<[format]>, ...);
66         int asiprintf( char **<[strp]>,
67                          const char *<[format]>, ...);
68         char *asniprintf( char *<[str]>,
69                             size_t *<[size]>, const char *<[format]>, ...);
70 
71 DESCRIPTION
72         <<iprintf>>, <<fiprintf>>, <<siprintf>>, <<sniprintf>>,
73         <<asiprintf>>, and <<asniprintf>> are the same as <<printf>>,
74         <<fprintf>>, <<sprintf>>, <<snprintf>>, <<asprintf>>, and
75         <<asnprintf>>, respectively, except that they restrict usage
76         to non-floating-point format specifiers.
77 
78         <<_iprintf_r>>, <<_fiprintf_r>>, <<_asiprintf_r>>,
79         <<_siprintf_r>>, <<_sniprintf_r>>, <<_asniprintf_r>> are
80         simply reentrant versions of the functions above.
81 
82 RETURNS
83 Similar to <<printf>>, <<fprintf>>, <<sprintf>>, <<snprintf>>, <<asprintf>>,
84 and <<asnprintf>>.
85 
86 PORTABILITY
87 <<iprintf>>, <<fiprintf>>, <<siprintf>>, <<sniprintf>>, <<asiprintf>>,
88 and <<asniprintf>> are newlib extensions.
89 
90 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
91 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
92 */
93 
94 #define _DEFAULT_SOURCE
95 #include <_ansi.h>
96 #include <stdio.h>
97 #include <stdarg.h>
98 #include <limits.h>
99 #include "local.h"
100 
101 int
siprintf(char * str,const char * fmt,...)102 siprintf (
103        char *str,
104        const char *fmt, ...)
105 {
106   int ret;
107   va_list ap;
108   FILE f;
109 
110   f._flags = __SWR | __SSTR;
111   f._flags2 = 0;
112   f._bf._base = f._p = (unsigned char *) str;
113   f._bf._size = f._w = INT_MAX;
114   f._file = -1;  /* No file. */
115   va_start (ap, fmt);
116   ret = svfiprintf ( &f, fmt, ap);
117   va_end (ap);
118   *f._p = 0;
119   return (ret);
120 }
121