Artifactspublic-v0

curl

master
ply4 git calls31 ms291 KiB3 cachedprotocol v2
293 lines10 KiBRaw

NAME

curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf, curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf, curl_mvsprintf - formatted output conversion

SYNOPSIS

c
#include <curl/mprintf.h>

int curl_mprintf(const char *format, ...);
int curl_mfprintf(FILE *fd, const char *format, ...);
int curl_msprintf(char *buffer, const char *format, ...);
int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...);
int curl_mvprintf(const char *format, va_list args);
int curl_mvfprintf(FILE *fd, const char *format, va_list args);
int curl_mvsprintf(char *buffer, const char *format, va_list args);
int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
                    va_list args);
char *curl_maprintf(const char *format , ...);
char *curl_mvaprintf(const char *format, va_list args);

DESCRIPTION

These functions produce output according to the format string and given arguments. They are mostly clones of the well-known C-style functions but there are slight differences in behavior.

We discourage users from using any of these functions in new applications.

Functions in the curl_mprintf() family produce output according to a format as described below. The functions curl_mprintf() and curl_mvprintf() write output to stdout, the standard output stream; curl_mfprintf() and curl_mvfprintf() write output to the given output stream; curl_msprintf(), curl_msnprintf(), curl_mvsprintf(), and curl_mvsnprintf() write to the character string buffer.

The functions curl_msnprintf() and curl_mvsnprintf() write at most maxlength bytes (including the null-terminator byte ('0')) to buffer.

The functions curl_mvprintf(), curl_mvfprintf(), curl_mvsprintf(), curl_mvsnprintf() are equivalent to the functions curl_mprintf(), curl_mfprintf(), curl_msprintf(), curl_msnprintf(), respectively, except that they are called with a va_list instead of a variable number of arguments. These functions do not call the va_end macro. Because they invoke the va_arg macro, the value of ap is undefined after the call.

The functions curl_maprintf() and curl_mvaprintf() return the output string as pointer to a newly allocated memory area. The returned string may not be overwritten and must be curl_free(3)ed by the receiver.

All of these functions write the output under the control of a format string that specifies how subsequent arguments are converted for output.

FORMAT STRING

The format string is composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character %, and ends with a conversion specifier. In between there may be (in this order) zero or more flags, an optional minimum field width, an optional precision and an optional length modifier.

The $ modifier

The arguments must correspond properly with the conversion specifier. By default, the arguments are used in the order given, where each '' (see Field width and Precision below) and each conversion specifier asks for the next argument (and it is an error if insufficiently many arguments are given). One can also specify explicitly which argument is taken, at each place where an argument is required, by writing "%m$" instead of '%' and "m$" instead of '*', where the decimal integer m denotes the position in the argument list of the desired argument, indexed starting from 1. Thus,

c
    curl_mprintf("%*d", width, num);

and

c
    curl_mprintf("%2$*1$d", width, num);

are equivalent. The second style allows repeated references to the same argument.

If the style using '$' is used, it must be used throughout for all conversions taking an argument and all width and precision arguments, but it may be mixed with "%%" formats, which do not consume an argument. There may be no gaps in the numbers of arguments specified using '$'; for example, if arguments 1 and 3 are specified, argument 2 must also be specified somewhere in the format string.

Flag characters

The character % is followed by zero or more of the following flags:

#

The value should be converted to its "alternate form".

0

The value should be zero padded.

-

The converted value is to be left adjusted on the field boundary. (The default is right justification.) The converted value is padded on the right with blanks, rather than on the left with blanks or zeros. A '-' overrides a &'0' if both are given.

(space)

(a space: ' ') A blank should be left before a positive number (or empty string) produced by a signed conversion.

+

A sign (+ or -) should always be placed before a number produced by a signed conversion. By default, a sign is used only for negative numbers. A '+' overrides a space if both are used.

Field width

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

Precision

An optional precision in the form of a period ('.') followed by an optional decimal digit string. Instead of a decimal digit string one may write "" or "m$" (for some decimal integer m) to specify that the precision is given in the next argument, or in the m-th argument, respectively, which must be of type int. If the precision is given as a single '.', the precision is taken to be zero. A negative precision is taken as if the precision were omitted. This gives the minimum number of digits to appear for d, i, o, u, x, and X conversions, the number of digits to appear after the radix character for a, A, e, E, f, and F conversions, the maximum number of significant digits for g and G conversions, or the maximum number of characters to be printed from a string for s and S conversions.

Length modifier

h

A following integer conversion corresponds to a short or unsigned short argument.

l

(ell) A following integer conversion corresponds to a long or unsigned long argument, or a following n conversion corresponds to a pointer to a long argument

ll

(ell-ell). A following integer conversion corresponds to a long long or unsigned long long argument, or a following n conversion corresponds to a pointer to a long long argument.

q

A synonym for ll.

L

A following a, A, e, E, f, F, g, or G conversion corresponds to a long double argument.

z

A following integer conversion corresponds to a size_t or ssize_t argument.

Conversion specifiers

A character that specifies the type of conversion to be applied. The conversion specifiers and their meanings are:

d, i

The int argument is converted to signed decimal notation. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros. The default precision is 1. When 0 is printed with an explicit precision 0, the output is empty.

o, u, x, X

The unsigned int argument is converted to unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal (x and X) notation. The letters abcdef are used for x conversions; the letters ABCDEF are used for X conversions. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros. The default precision is 1. When 0 is printed with an explicit precision 0, the output is empty.

e, E

The double argument is rounded and output in the style "[-]d.ddde{+|-}dd"

f, F

The double argument is rounded and output to decimal notation in the style "[-]ddd.ddd".

g, G

The double argument is converted in style f or e.

c

The int argument is converted to an unsigned char, and the resulting character is written.

s

The const char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a null-terminator byte. If a precision is specified, no more than the number specified are written. If a precision is given, no null byte need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a null-terminator byte.

p

The void * pointer argument is printed in hexadecimal.

n

The number of characters written so far is stored into the integer pointed to by the corresponding argument.

%

A '%' symbol is written. No argument is converted.

%PROTOCOLS%

EXAMPLE

c
static const char *name = "John";

int main(void)
{
  curl_mprintf("My name is %s\n", name);
  curl_mprintf("Pi is almost %f\n", (double)25.0 / 8);
}

%AVAILABILITY%

RETURN VALUE

The curl_maprintf and curl_mvaprintf functions return a pointer to a newly allocated string, or NULL if it failed.

All other functions return the number of characters actually printed (excluding the null byte used to end output to strings). Note that this sometimes differ from how the POSIX versions of these functions work.

Since libcurl 8.23.0 curl_mfprintf, curl_mprintf, curl_mvfprintf and curl_mvprintf return -1 when the output fails.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_printf
5Section: 3
6Source: libcurl
7See-also:
8 - fprintf (3)
9 - printf (3)
10 - sprintf (3)
11 - vprintf (3)
12Protocol:
13 - All
14Added-in: 7.1
15---
17# NAME
19curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf,
20curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf,
21curl_mvsprintf - formatted output conversion
23# SYNOPSIS
25~~~c
26#include <curl/mprintf.h>
28int curl_mprintf(const char *format, ...);
29int curl_mfprintf(FILE *fd, const char *format, ...);
30int curl_msprintf(char *buffer, const char *format, ...);
31int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...);
32int curl_mvprintf(const char *format, va_list args);
33int curl_mvfprintf(FILE *fd, const char *format, va_list args);
34int curl_mvsprintf(char *buffer, const char *format, va_list args);
35int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
36 va_list args);
37char *curl_maprintf(const char *format , ...);
38char *curl_mvaprintf(const char *format, va_list args);
39~~~
41# DESCRIPTION
43These functions produce output according to the format string and given
44arguments. They are mostly clones of the well-known C-style functions but
45there are slight differences in behavior.
47We discourage users from using any of these functions in new applications.
49Functions in the curl_mprintf() family produce output according to a format as
50described below. The functions **curl_mprintf()** and **curl_mvprintf()**
51write output to stdout, the standard output stream; **curl_mfprintf()** and
52**curl_mvfprintf()** write output to the given output stream;
53**curl_msprintf()**, **curl_msnprintf()**, **curl_mvsprintf()**, and
54**curl_mvsnprintf()** write to the character string **buffer**.
56The functions **curl_msnprintf()** and **curl_mvsnprintf()** write at most
57*maxlength* bytes (including the null-terminator byte ('0')) to
58*buffer*.
60The functions **curl_mvprintf()**, **curl_mvfprintf()**,
61**curl_mvsprintf()**, **curl_mvsnprintf()** are equivalent to the
62functions **curl_mprintf()**, **curl_mfprintf()**, **curl_msprintf()**,
63**curl_msnprintf()**, respectively, except that they are called with a
64*va_list* instead of a variable number of arguments. These functions do
65not call the *va_end* macro. Because they invoke the *va_arg* macro,
66the value of *ap* is undefined after the call.
68The functions **curl_maprintf()** and **curl_mvaprintf()** return the
69output string as pointer to a newly allocated memory area. The returned string
70may not be overwritten and must be curl_free(3)ed by the receiver.
72All of these functions write the output under the control of a format string
73that specifies how subsequent arguments are converted for output.
75# FORMAT STRING
77The format string is composed of zero or more directives: ordinary characters
78(not %), which are copied unchanged to the output stream; and conversion
79specifications, each of which results in fetching zero or more subsequent
80arguments. Each conversion specification is introduced by the character %, and
81ends with a conversion specifier. In between there may be (in this order) zero
82or more *flags*, an optional minimum *field width*, an optional
83*precision* and an optional *length modifier*.
85# The $ modifier
87The arguments must correspond properly with the conversion specifier. By
88default, the arguments are used in the order given, where each '*' (see Field
89width and Precision below) and each conversion specifier asks for the next
90argument (and it is an error if insufficiently many arguments are given). One
91can also specify explicitly which argument is taken, at each place where an
92argument is required, by writing "%m$" instead of '%' and "*m$" instead
93of '*', where the decimal integer m denotes the position in the argument list
94of the desired argument, indexed starting from 1. Thus,
95~~~c
96 curl_mprintf("%*d", width, num);
97~~~
98and
99~~~c
100 curl_mprintf("%2$*1$d", width, num);
101~~~
102are equivalent. The second style allows repeated references to the same
103argument.
105If the style using '$' is used, it must be used throughout for all conversions
106taking an argument and all width and precision arguments, but it may be mixed
107with "%%" formats, which do not consume an argument. There may be no gaps in
108the numbers of arguments specified using '$'; for example, if arguments 1 and
1093 are specified, argument 2 must also be specified somewhere in the format
110string.
112# Flag characters
114The character % is followed by zero or more of the following flags:
116## #
118The value should be converted to its "alternate form".
120## 0
122The value should be zero padded.
124## -
126The converted value is to be left adjusted on the field boundary. (The default
127is right justification.) The converted value is padded on the right with
128blanks, rather than on the left with blanks or zeros. A '-' overrides a &'0'
129if both are given.
131## (space)
133(a space: ' ') A blank should be left before a positive number (or empty
134string) produced by a signed conversion.
136## +
138A sign (+ or -) should always be placed before a number produced by a signed
139conversion. By default, a sign is used only for negative numbers. A '+'
140overrides a space if both are used.
142# Field width
144An optional decimal digit string (with nonzero first digit) specifying a
145minimum field width. If the converted value has fewer characters than the
146field width, it gets padded with spaces on the left (or right, if the
147left-adjustment flag has been given). Instead of a decimal digit string one
148may write "*" or "*m$" (for some decimal integer m) to specify that the field
149width is given in the next argument, or in the *m-th* argument,
150respectively, which must be of type int. A negative field width is taken as
151a '-' flag followed by a positive field width. In no case does a nonexistent
152or small field width cause truncation of a field; if the result of a
153conversion is wider than the field width, the field is expanded to contain the
154conversion result.
156# Precision
158An optional precision in the form of a period ('.') followed by an optional
159decimal digit string. Instead of a decimal digit string one may write "*" or
160"*m$" (for some decimal integer m) to specify that the precision is given in
161the next argument, or in the *m-th* argument, respectively, which must be of
162type int. If the precision is given as a single '.', the precision is taken to
163be zero. A negative precision is taken as if the precision were omitted. This
164gives the minimum number of digits to appear for **d**, **i**, **o**, **u**,
165**x**, and **X** conversions, the number of digits to appear after the radix
166character for **a**, **A**, **e**, **E**, **f**, and **F** conversions, the
167maximum number of significant digits for **g** and **G** conversions, or the
168maximum number of characters to be printed from a string for **s** and **S**
169conversions.
171# Length modifier
173## h
175A following integer conversion corresponds to a *short* or *unsigned short*
176argument.
178## l
180(ell) A following integer conversion corresponds to a *long* or
181*unsigned long* argument, or a following n conversion corresponds to a
182pointer to a long argument
184## ll
186(ell-ell). A following integer conversion corresponds to a *long long* or
187*unsigned long long* argument, or a following n conversion corresponds to
188a pointer to a *long long* argument.
190## q
192A synonym for **ll**.
194## L
196A following a, A, e, E, f, F, g, or G conversion corresponds to a long double
197argument.
199## z
201A following integer conversion corresponds to a *size_t* or *ssize_t*
202argument.
204# Conversion specifiers
206A character that specifies the type of conversion to be applied. The
207conversion specifiers and their meanings are:
209## d, i
211The int argument is converted to signed decimal notation. The precision, if
212any, gives the minimum number of digits that must appear; if the converted
213value requires fewer digits, it is padded on the left with zeros. The default
214precision is 1. When 0 is printed with an explicit precision 0, the output is
215empty.
217## o, u, x, X
219The unsigned int argument is converted to unsigned octal (o), unsigned decimal
220(u), or unsigned hexadecimal (**x** and **X**) notation. The letters
221*abcdef* are used for **x** conversions; the letters *ABCDEF* are
222used for **X** conversions. The precision, if any, gives the minimum number
223of digits that must appear; if the converted value requires fewer digits, it
224is padded on the left with zeros. The default precision is 1. When 0 is
225printed with an explicit precision 0, the output is empty.
227## e, E
229The double argument is rounded and output in the style **"[-]d.ddde{+|-}dd"**
231## f, F
233The double argument is rounded and output to decimal notation in the style
234**"[-]ddd.ddd"**.
236## g, G
238The double argument is converted in style f or e.
240## c
242The int argument is converted to an unsigned char, and the resulting character
243is written.
245## s
247The *const char ** argument is expected to be a pointer to an array of
248character type (pointer to a string). Characters from the array are written up
249to (but not including) a null-terminator byte. If a precision is specified,
250no more than the number specified are written. If a precision is given, no
251null byte need be present; if the precision is not specified, or is greater
252than the size of the array, the array must contain a null-terminator byte.
254## p
256The *void ** pointer argument is printed in hexadecimal.
258## n
260The number of characters written so far is stored into the integer pointed to
261by the corresponding argument.
263## %
265A '%' symbol is written. No argument is converted.
267# %PROTOCOLS%
269# EXAMPLE
271~~~c
272static const char *name = "John";
274int main(void)
276 curl_mprintf("My name is %s\n", name);
277 curl_mprintf("Pi is almost %f\n", (double)25.0 / 8);
279~~~
281# %AVAILABILITY%
283# RETURN VALUE
285The **curl_maprintf** and **curl_mvaprintf** functions return a pointer to
286a newly allocated string, or NULL if it failed.
288All other functions return the number of characters actually printed
289(excluding the null byte used to end output to strings). Note that this
290sometimes differ from how the POSIX versions of these functions work.
292Since libcurl 8.23.0 curl_mfprintf, curl_mprintf, curl_mvfprintf and
293curl_mvprintf return -1 when the output fails.
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=26
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2003.8 KiB · hit26 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3876
git.response.cache=HIT
git.response.duration_ms=26
git.fetch.wants=dc778b59582434a8ab19f77177fff4b823f6d5da
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3876
git.pkt.payload.max=3855
git.sideband.band1.bytes=3854
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e1cac59cb3c6f8
Request
4bda084b…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format