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           curl_mprintf("%*d", width, num);
82       and
83           curl_mprintf("%2$*1$d", width, num);
84       are equivalent. The second style allows repeated references to the same
85       argument.
86
87       If the style using '$' is used, it must be used throughout for all con‐
88       versions  taking an argument and all width and precision arguments, but
89       it may be mixed with "%%" formats, which do not  consume  an  argument.
90       There  may  be no gaps in the numbers of arguments specified using '$';
91       for example, if arguments 1 and 3 are specified, argument 2  must  also
92       be specified somewhere in the format string.
93
94

Flag characters

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

Field width

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

Precision

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

Length modifier

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

Conversion specifiers

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

EXAMPLE

209         mprintf("My name is %s\n", name);
210         mprintf("Pi is almost %f\n", 25/8);
211

AVAILABILITY

213       These functions will be removed from the public libcurl API in the  fu‐
214       ture. Do not use them in new programs or projects.
215

RETURN VALUE

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

SEE ALSO

225       printf(3), sprintf(3), fprintf(3), vprintf(3)
226
227
228
229libcurl 8.0.1                  January 02, 2023                 curl_printf(3)
Impressum