1curl_printf(3)                  libcurl Manual                  curl_printf(3)
2
3
4

NAME

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

SYNOPSIS

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       int curl_mvprintf(const char *format, va_list args);
18       int curl_mvfprintf(FILE *fd, const char *format, va_list args);
19       int curl_mvsprintf(char *buffer, const char *format, va_list args);
20       int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
21                           va_list args);
22       char *curl_maprintf(const char *format , ...);
23       char *curl_mvaprintf(const char *format, va_list args);
24

DESCRIPTION

26       These functions produce output according to the format string and given
27       arguments. They are mostly clones of the well-known  C-style  functions
28       but there are slight differences in behavior.
29
30       We  discourage  users from using any of these functions in new applica‐
31       tions.
32
33       Functions in the curl_mprintf() family produce output  according  to  a
34       format   as   described   below.   The   functions  curl_mprintf()  and
35       curl_mvprintf() write output to stdout,  the  standard  output  stream;
36       curl_mfprintf()  and  curl_mvfprintf() write output to the given output
37       stream;  curl_msprintf(),   curl_msnprintf(),   curl_mvsprintf(),   and
38       curl_mvsnprintf() write to the character string buffer.
39
40       The  functions  curl_msnprintf()  and  curl_mvsnprintf()  write at most
41       maxlength bytes (including the terminating null byte ('\0')) to buffer.
42
43       The  functions  curl_mvprintf(),  curl_mvfprintf(),   curl_mvsprintf(),
44       curl_mvsnprintf()  are  equivalent  to  the  functions  curl_mprintf(),
45       curl_mfprintf(), curl_msprintf(), curl_msnprintf(),  respectively,  ex‐
46       cept  that  they are called with a va_list instead of a variable number
47       of arguments. These functions do not call  the  va_end  macro.  Because
48       they  invoke  the  va_arg macro, the value of ap is undefined after the
49       call.
50
51       The functions curl_maprintf() and curl_mvaprintf()  return  the  output
52       string as pointer to a newly allocated memory area. The returned string
53       must be curl_free(3)ed by the receiver.
54
55       All of these functions write the output under the control of  a  format
56       string  that  specifies how subsequent arguments are converted for out‐
57       put.
58
59

FORMAT STRING

61       The format string is composed of  zero  or  more  directives:  ordinary
62       characters  (not  %),  which are copied unchanged to the output stream;
63       and conversion specifications, each of which results in  fetching  zero
64       or  more  subsequent arguments. Each conversion specification is intro‐
65       duced by the character %, and ends with a conversion specifier. In  be‐
66       tween there may be (in this order) zero or more flags, an optional min‐
67       imum field width, an optional precision and an  optional  length  modi‐
68       fier.
69
70

The $ modifier

72       The  arguments  must correspond properly with the conversion specifier.
73       By default, the arguments are used in the order given, where  each  '*'
74       (see  Field  width  and  Precision below) and each conversion specifier
75       asks for the next argument (and it is an error if  insufficiently  many
76       arguments are given). One can also specify explicitly which argument is
77       taken, at each place where an argument is required,  by  writing  "%m$"
78       instead  of  '%'  and "*m$" instead of '*', where the decimal integer m
79       denotes the position in the argument list of the desired argument,  in‐
80       dexed starting from 1. Thus,
81
82           curl_mprintf("%*d", width, num);
83
84       and
85
86           curl_mprintf("%2$*1$d", width, num);
87
88       are equivalent. The second style allows repeated references to the same
89       argument.
90
91       If the style using '$' is used, it must be used throughout for all con‐
92       versions  taking an argument and all width and precision arguments, but
93       it may be mixed with "%%" formats, which do not  consume  an  argument.
94       There may be no gaps in the numbers of argu‐ ments specified using '$';
95       for example, if arguments 1 and 3 are specified, argument 2  must  also
96       be specified somewhere in the format string.
97
98

Flag characters

100       The character % is followed by zero or more of the following flags:
101
102       #      The value should be converted to its "alternate form".
103
104       0      The value should be zero padded.
105
106       -      The  converted  value is to be left adjusted on the field bound‐
107              ary.  (The default is right justification.)  The converted value
108              is padded on the right with blanks, rather than on the left with
109              blanks or zeros. A '-' overrides a '0' if both are given.
110
111       ' '    (a space) A blank should be left before a  positive  number  (or
112              empty string) produced by a signed conversion.
113
114       +      A sign (+ or -) should always be placed before a number produced
115              by a signed conversion. By default, a sign is used only for neg‐
116              ative numbers. A '+' overrides a space if both are used.
117

Field width

119       An  optional decimal digit string (with nonzero first digit) specifying
120       a minimum field width. If the converted value has fewer characters than
121       the  field  width, it will be padded with spaces on the left (or right,
122       if the left-adjustment flag has been given). Instead of a decimal digit
123       string one may write "*" or "*m$" (for some decimal integer m) to spec‐
124       ify that the field width is given in the next argument, or in the  m-th
125       argument,  respec‐  tively, which must be of type int. A negative field
126       width is taken as a '-' flag followed by a positive field width. In  no
127       case  does  a  nonexistent  or  small field width cause truncation of a
128       field; if the result of a conversion is wider than the field width, the
129       field is expanded to contain the conversion result.
130

Precision

132       An  optional precision in the form of a period ('.') followed by an op‐
133       tional decimal digit string. Instead of a decimal digit string one  may
134       write  "*"  or  "*m$"  (for some decimal integer m) to specify that the
135       precision is given in the next argument, or in the m-th  argument,  re‐
136       spectively,  which  must  be  of type int. If the precision is given as
137       just '.', the precision is taken to be zero. A  negative  precision  is
138       taken  as  if the precision were omitted. This gives the minimum number
139       of digits to appear for d, i, o, u, x, and X conversions, the number of
140       digits  to  appear  after  the radix character for a, A, e, E, f, and F
141       conversions, the maximum number of significant digits for g and G  con‐
142       versions,  or  the  maximum  number  of characters to be printed from a
143       string for s and S conversions.
144

Length modifier

146       h      A following integer conversion corresponds to  a  short  or  un‐
147              signed short argument.
148
149       l      (ell)  A  following  integer conversion corresponds to a long or
150              unsigned long argument, or a following n conversion  corresponds
151              to a pointer to a long argument
152
153       ll     (ell-ell).  A following integer conversion corresponds to a long
154              long or unsigned long long argument, or a following n conversion
155              corresponds to a pointer to a long long argument.
156
157       q      A synonym for ll.
158
159       L      A  following a, A, e, E, f, F, g, or G conversion corresponds to
160              a long double argument.
161
162       z      A following  integer  conversion  corresponds  to  a  size_t  or
163              ssize_t argument.
164

Conversion specifiers

166       A  character  that  specifies the type of conversion to be applied. The
167       conversion specifiers and their meanings are:
168
169       d, i   The int argument is converted to signed  decimal  notation.  The
170              precision,  if any, gives the minimum number of digits that must
171              appear; if the converted value  requires  fewer  digits,  it  is
172              padded  on the left with zeros. The default precision is 1. When
173              0 is printed with an explicit precision 0, the output is empty.
174
175       o, u, x, X
176              The unsigned int argument is converted to  unsigned  octal  (o),
177              unsigned  decimal  (u),  or unsigned hexadecimal (x and X) nota‐
178              tion. The letters abcdef are used for x conversions; the letters
179              ABCDEF  are used for X conversions. The precision, if any, gives
180              the minimum number of digits that must appear; if the  converted
181              value  requires  fewer digits, it is padded on the left with ze‐
182              ros. The default precision is 1. When 0 is printed with  an  ex‐
183              plicit precision 0, the output is empty.
184
185       e, E   The   double  argument  is  rounded  and  output  in  the  style
186              "[-]d.ddde±dd"
187
188       f, F   The double argument is rounded and output to  decimal  notiation
189              in the style [-]ddd.ddd.
190
191       g, G   The double argument is converted in style f or e.
192
193       c      The  int  argument is converted to an unsigned char, and the re‐
194              sulting character is written.
195
196       s      The const char * argument is expected to be a pointer to an  ar‐
197              ray of character type (pointer to a string). Characters from the
198              array are written up to (but not including) a  terminating  null
199              byte. If a precision is specified, no more than the number spec‐
200              ified are written. If a precision is given, no null byte need be
201              present;  if  the precision is not specified, or is greater than
202              the size of the array, the array must contain a terminating null
203              byte.
204
205       p      The void * pointer argument is printed in hexadecimal.
206
207       n      The number of characters written so far is stored into the inte‐
208              ger pointed to by the corresponding argument.
209
210       %      A '%' is written. No argument is converted.
211

EXAMPLE

213         mprintf("My name is %s\n", name);
214         mprintf("Pi is almost %f\n", 25/8);
215

AVAILABILITY

217       These functions will be removed from the public libcurl API in the  fu‐
218       ture. Do not use them in new programs or projects.
219

RETURN VALUE

221       The  curl_maprintf  and  curl_mvaprintf functions return a pointer to a
222       newly allocated string, or NULL if it failed.
223
224       All other functions return the number of  characters  actually  printed
225       (excluding the null byte used to end output to strings). Note that this
226       sometimes differ from how the POSIX versions of these functions work.
227

SEE ALSO

229       printf(3), sprintf(3), fprintf(3), vprintf(3)
230
231
232
233libcurl 7.85.0                   May 17, 2022                   curl_printf(3)
Impressum