1curl_printf(3) libcurl Manual curl_printf(3)
2
3
4
6 curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf,
7 curl_msprintf curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvs‐
8 nprintf, curl_mvsprintf - formatted output conversion
9
11 #include <curl/mprintf.h>
12
13 int curl_mprintf(const char *format, ...);
14 int curl_mfprintf(FILE *fd, const char *format, ...);
15 int curl_msprintf(char *buffer, const char *format, ...);
16 int curl_msnprintf(char *buffer, size_t maxlength, const char *format,
17 ...);
18 int curl_mvprintf(const char *format, va_list args);
19 int curl_mvfprintf(FILE *fd, const char *format, va_list args);
20 int curl_mvsprintf(char *buffer, const char *format, va_list args);
21 int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
22 va_list args);
23 char *curl_maprintf(const char *format, ...);
24 char *curl_mvaprintf(const char *format, va_list args);
25
27 These functions produce output according to the format string and given
28 arguments. They are mostly clones of the well-known C-style functions
29 but there are slight differences in behavior.
30
31 We discourage users from using any of these functions in new applica‐
32 tions.
33
34 Functions in the curl_mprintf() family produce output according to a
35 format as described below. The functions curl_mprintf() and
36 curl_mvprintf() write output to stdout, the standard output stream;
37 curl_mfprintf() and curl_mvfprintf() write output to the given output
38 stream; curl_msprintf(), curl_msnprintf(), curl_mvsprintf(), and
39 curl_mvsnprintf() write to the character string buffer.
40
41 The functions curl_msnprintf() and curl_mvsnprintf() write at most
42 maxlength bytes (including the terminating null byte ('\0')) to buffer.
43
44 The functions curl_mvprintf(), curl_mvfprintf(), curl_mvsprintf(),
45 curl_mvsnprintf() are equivalent to the functions curl_mprintf(),
46 curl_mfprintf(), curl_msprintf(), curl_msnprintf(), respectively, ex‐
47 cept that they are called with a va_list instead of a variable number
48 of arguments. These functions do not call the va_end macro. Because
49 they invoke the va_arg macro, the value of ap is undefined after the
50 call.
51
52 The functions curl_maprintf() and curl_mvaprintf() return the output
53 string as pointer to a newly allocated memory area. The returned string
54 must be curl_free(3)ed by the receiver.
55
56 All of these functions write the output under the control of a format
57 string that specifies how subsequent arguments are converted for out‐
58 put.
59
60
62 The format string is composed of zero or more directives: ordinary
63 characters (not %), which are copied unchanged to the output stream;
64 and conversion specifications, each of which results in fetching zero
65 or more subsequent arguments. Each conversion specification is intro‐
66 duced by the character %, and ends with a conversion specifier. In be‐
67 tween there may be (in this order) zero or more flags, an optional min‐
68 imum field width, an optional precision and an optional length modi‐
69 fier.
70
71
73 The arguments must correspond properly with the conversion specifier.
74 By default, the arguments are used in the order given, where each '*'
75 (see Field width and Precision below) and each conversion specifier
76 asks for the next argument (and it is an error if insufficiently many
77 arguments are given). One can also specify explicitly which argument
78 is taken, at each place where an argument is required, by writing "%m$"
79 instead of '%' and "*m$" instead of '*', where the decimal integer m
80 denotes the position in the argument list of the desired argument, in‐
81 dexed starting from 1. Thus,
82
83 curl_mprintf("%*d", width, num);
84
85 and
86
87 curl_mprintf("%2$*1$d", width, num);
88
89 are equivalent. The second style allows repeated references to the same
90 argument.
91
92 If the style using '$' is used, it must be used throughout for all con‐
93 versions taking an argument and all width and precision arguments, but
94 it may be mixed with "%%" formats, which do not consume an argument.
95 There may be no gaps in the numbers of argu‐ ments specified using '$';
96 for example, if arguments 1 and 3 are specified, argument 2 must also
97 be specified somewhere in the format string.
98
99
101 The character % is followed by zero or more of the following flags:
102
103 # The value should be converted to its "alternate form".
104
105 0 The value should be zero padded.
106
107 - The converted value is to be left adjusted on the field bound‐
108 ary. (The default is right justification.) The converted value
109 is padded on the right with blanks, rather than on the left with
110 blanks or zeros. A '-' overrides a '0' if both are given.
111
112 ' ' (a space) A blank should be left before a positive number (or
113 empty string) produced by a signed conversion.
114
115 + A sign (+ or -) should always be placed before a number produced
116 by a signed conversion. By default, a sign is used only for neg‐
117 ative numbers. A '+' overrides a space if both are used.
118
120 An optional decimal digit string (with nonzero first digit) specifying
121 a minimum field width. If the converted value has fewer characters than
122 the field width, it will be padded with spaces on the left (or right,
123 if the left-adjustment flag has been given). Instead of a decimal digit
124 string one may write "*" or "*m$" (for some decimal integer m) to spec‐
125 ify that the field width is given in the next argument, or in the m-th
126 argument, respec‐ tively, which must be of type int. A negative field
127 width is taken as a '-' flag followed by a positive field width. In no
128 case does a nonexistent or small field width cause truncation of a
129 field; if the result of a conversion is wider than the field width, the
130 field is expanded to contain the conversion result.
131
133 An optional precision in the form of a period ('.') followed by an op‐
134 tional decimal digit string. Instead of a decimal digit string one may
135 write "*" or "*m$" (for some decimal integer m) to specify that the
136 precision is given in the next argument, or in the m-th argument, re‐
137 spectively, which must be of type int. If the precision is given as
138 just '.', the precision is taken to be zero. A negative precision is
139 taken as if the precision were omitted. This gives the minimum number
140 of digits to appear for d, i, o, u, x, and X conversions, the number of
141 digits to appear after the radix character for a, A, e, E, f, and F
142 conversions, the maximum number of significant digits for g and G con‐
143 versions, or the maximum number of characters to be printed from a
144 string for s and S conversions.
145
147 h A following integer conversion corresponds to a short or un‐
148 signed short argument.
149
150 l (ell) A following integer conversion corresponds to a long or
151 unsigned long argument, or a following n conversion corresponds
152 to a pointer to a long argument
153
154 ll (ell-ell). A following integer conversion corresponds to a long
155 long or unsigned long long argument, or a following n conversion
156 corresponds to a pointer to a long long argument.
157
158 q A synonym for ll.
159
160 L A following a, A, e, E, f, F, g, or G conversion corresponds to
161 a long double argument.
162
163 z A following integer conversion corresponds to a size_t or
164 ssize_t argument.
165
167 A character that specifies the type of conversion to be applied. The
168 conversion specifiers and their meanings are:
169
170 d, i The int argument is converted to signed decimal notation. The
171 precision, if any, gives the minimum number of digits that must
172 appear; if the converted value requires fewer digits, it is
173 padded on the left with zeros. The default precision is 1. When
174 0 is printed with an explicit precision 0, the output is empty.
175
176 o, u, x, X
177 The unsigned int argument is converted to unsigned octal (o),
178 unsigned decimal (u), or unsigned hexadecimal (x and X) nota‐
179 tion. The letters abcdef are used for x conversions; the let‐
180 ters ABCDEF are used for X conversions. The precision, if any,
181 gives the minimum number of digits that must appear; if the con‐
182 verted value requires fewer digits, it is padded on the left
183 with zeros. The default precision is 1. When 0 is printed with
184 an explicit precision 0, the output is empty.
185
186 e, E The double argument is rounded and output in the style
187 "[-]d.ddde±dd"
188
189 f, F The double argument is rounded and output to decimal notiation
190 in the style [-]ddd.ddd.
191
192 g, G The double argument is converted in style f or e.
193
194 c The int argument is converted to an unsigned char, and the re‐
195 sulting character is written.
196
197 s The const char * argument is expected to be a pointer to an ar‐
198 ray of character type (pointer to a string). Characters from the
199 array are written up to (but not including) a terminating null
200 byte. If a precision is specified, no more than the number spec‐
201 ified are written. If a precision is given, no null byte need be
202 present; if the precision is not specified, or is greater than
203 the size of the array, the array must contain a terminating null
204 byte.
205
206 p The void * pointer argument is printed in hexadecimal.
207
208 n The number of characters written so far is stored into the inte‐
209 ger pointed to by the corresponding argument.
210
211 % A '%' is written. No argument is converted.
212
214 These functions will be removed from the public libcurl API in the fu‐
215 ture. Do not use them in new programs or projects.
216
218 The curl_maprintf and curl_mvaprintf functions return a pointer to a
219 newly allocated string, or NULL if it failed.
220
221 All other functions return the number of characters actually printed
222 (excluding the null byte used to end output to strings). Note that this
223 sometimes differ from how the POSIX versions of these functions work.
224
226 printf(3), sprintf(3), fprintf(3), vprintf(3)
227
228
229
230libcurl 7.79.1 July 07, 2021 curl_printf(3)