2011-03-12 07:14:32 +08:00
|
|
|
.\" **************************************************************************
|
|
|
|
.\" * _ _ ____ _
|
|
|
|
.\" * Project ___| | | | _ \| |
|
|
|
|
.\" * / __| | | | |_) | |
|
|
|
|
.\" * | (__| |_| | _ <| |___
|
|
|
|
.\" * \___|\___/|_| \_\_____|
|
|
|
|
.\" *
|
2021-05-05 17:07:40 +08:00
|
|
|
.\" * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-12 07:14:32 +08:00
|
|
|
.\" *
|
|
|
|
.\" * This software is licensed as described in the file COPYING, which
|
|
|
|
.\" * you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
.\" * are also available at https://curl.se/docs/copyright.html.
|
2011-03-12 07:14:32 +08:00
|
|
|
.\" *
|
|
|
|
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
.\" * copies of the Software, and permit persons to whom the Software is
|
|
|
|
.\" * furnished to do so, under the terms of the COPYING file.
|
|
|
|
.\" *
|
|
|
|
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
.\" * KIND, either express or implied.
|
|
|
|
.\" *
|
|
|
|
.\" * SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
.\" *
|
2011-03-12 07:14:32 +08:00
|
|
|
.\" **************************************************************************
|
2004-04-30 16:38:08 +08:00
|
|
|
.TH curl_printf 3 "30 April 2004" "libcurl 7.12" "libcurl Manual"
|
2002-03-04 18:09:48 +08:00
|
|
|
.SH NAME
|
|
|
|
curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf
|
|
|
|
curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf,
|
|
|
|
curl_mvsprintf - formatted output conversion
|
|
|
|
.SH SYNOPSIS
|
2021-11-26 21:20:18 +08:00
|
|
|
.nf
|
|
|
|
#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);
|
|
|
|
.fi
|
2002-03-04 18:09:48 +08:00
|
|
|
.SH DESCRIPTION
|
2021-05-05 17:07:40 +08:00
|
|
|
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.
|
2002-03-04 18:09:48 +08:00
|
|
|
|
2021-05-05 17:07:40 +08:00
|
|
|
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
|
2021-11-26 15:46:59 +08:00
|
|
|
described below. The functions \fBcurl_mprintf()\fP and \fBcurl_mvprintf()\fP
|
2021-05-05 17:07:40 +08:00
|
|
|
write output to stdout, the standard output stream; \fBcurl_mfprintf()\fP and
|
|
|
|
\fBcurl_mvfprintf()\fP write output to the given output stream;
|
|
|
|
\fBcurl_msprintf()\fP, \fBcurl_msnprintf()\fP, \fBcurl_mvsprintf()\fP, and
|
|
|
|
\fBcurl_mvsnprintf()\fP write to the character string \fBbuffer\fP.
|
|
|
|
|
|
|
|
The functions \fBcurl_msnprintf()\fP and \fBcurl_mvsnprintf()\fP write at most
|
|
|
|
\fImaxlength\fP bytes (including the terminating null byte ('\\0')) to
|
|
|
|
\fIbuffer\fP.
|
|
|
|
|
|
|
|
The functions \fBcurl_mvprintf()\fP, \fBcurl_mvfprintf()\fP,
|
|
|
|
\fBcurl_mvsprintf()\fP, \fBcurl_mvsnprintf()\fP are equivalent to the
|
|
|
|
functions \fBcurl_mprintf()\fP, \fBcurl_mfprintf()\fP, \fBcurl_msprintf()\fP,
|
|
|
|
\fBcurl_msnprintf()\fP, respectively, except that they are called with a
|
2022-09-21 05:30:19 +08:00
|
|
|
\fIva_list\fP instead of a variable number of arguments. These functions do
|
|
|
|
not call the \fIva_end\fP macro. Because they invoke the \fIva_arg\fP macro,
|
|
|
|
the value of \fIap\fP is undefined after the call.
|
2021-05-05 17:07:40 +08:00
|
|
|
|
|
|
|
The functions \fBcurl_maprintf()\fP and \fBcurl_mvaprintf()\fP return the
|
|
|
|
output string as pointer to a newly allocated memory area. The returned string
|
|
|
|
must be \fIcurl_free(3)\fPed 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.
|
|
|
|
|
|
|
|
.SH 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 \fIflags\fP, an optional minimum \fIfield width\fP, an optional
|
|
|
|
\fIprecision\fP and an optional \fIlength modifier\fP.
|
|
|
|
|
|
|
|
.SH "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
|
2021-11-26 15:46:59 +08:00
|
|
|
argument (and it is an error if insufficiently many arguments are given). One
|
2021-05-05 17:07:40 +08:00
|
|
|
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
|
2021-11-26 15:46:59 +08:00
|
|
|
of the desired argument, indexed starting from 1. Thus,
|
2022-09-21 05:30:19 +08:00
|
|
|
.nf
|
2021-05-05 17:07:40 +08:00
|
|
|
curl_mprintf("%*d", width, num);
|
2022-09-21 05:30:19 +08:00
|
|
|
.fi
|
2021-05-05 17:07:40 +08:00
|
|
|
and
|
2022-09-21 05:30:19 +08:00
|
|
|
.nf
|
2021-05-05 17:07:40 +08:00
|
|
|
curl_mprintf("%2$*1$d", width, num);
|
2022-09-21 05:30:19 +08:00
|
|
|
.fi
|
2021-05-05 17:07:40 +08:00
|
|
|
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
|
2021-11-26 15:46:59 +08:00
|
|
|
with "%%" formats, which do not consume an argument. There may be no gaps in
|
2022-09-21 05:30:19 +08:00
|
|
|
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
|
2021-05-05 17:07:40 +08:00
|
|
|
string.
|
|
|
|
|
|
|
|
.SH "Flag characters"
|
|
|
|
The character % is followed by zero or more of the following flags:
|
|
|
|
.TP
|
|
|
|
.B #
|
|
|
|
The value should be converted to its "alternate form".
|
|
|
|
.TP
|
|
|
|
.B 0
|
|
|
|
The value should be zero padded.
|
|
|
|
.TP
|
|
|
|
.B -
|
|
|
|
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.
|
|
|
|
.TP
|
|
|
|
.B ' '
|
|
|
|
(a space) A blank should be left before a positive number (or empty string)
|
|
|
|
produced by a signed conversion.
|
|
|
|
.TP
|
|
|
|
.B +
|
|
|
|
A sign (+ or -) should always be placed before a number produced by a signed
|
2021-11-26 15:46:59 +08:00
|
|
|
conversion. By default, a sign is used only for negative numbers. A '+'
|
2021-05-05 17:07:40 +08:00
|
|
|
overrides a space if both are used.
|
|
|
|
.SH "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 will be 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
|
2022-09-21 05:30:19 +08:00
|
|
|
width is given in the next argument, or in the \fIm-th\fP 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.
|
2021-05-05 17:07:40 +08:00
|
|
|
.SH "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
|
2022-09-21 05:30:19 +08:00
|
|
|
the next argument, or in the \fIm-th\fP argument, respectively, which must be of
|
2021-05-05 17:07:40 +08:00
|
|
|
type int. If the precision is given as just '.', 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 \fBd\fP, \fBi\fP, \fBo\fP,
|
|
|
|
\fBu\fP, \fBx\fP, and \fBX\fP conversions, the number of digits to appear
|
|
|
|
after the radix character for \fBa\fP, \fBA\fP, \fBe\fP, \fBE\fP, \fBf\fP, and
|
|
|
|
\fBF\fP conversions, the maximum number of significant digits for \fBg\fP and
|
|
|
|
\fBG\fP conversions, or the maximum number of characters to be printed from a
|
|
|
|
string for \fBs\fP and \fBS\fP conversions.
|
|
|
|
.SH "Length modifier"
|
|
|
|
.TP
|
|
|
|
.B h
|
|
|
|
A following integer conversion corresponds to a \fIshort\fP or \fIunsigned
|
|
|
|
short\fP argument.
|
|
|
|
.TP
|
|
|
|
.B l
|
|
|
|
(ell) A following integer conversion corresponds to a \fIlong\fP or
|
|
|
|
\fIunsigned long\fP argument, or a following n conversion corresponds to a
|
|
|
|
pointer to a long argument
|
|
|
|
.TP
|
|
|
|
.B ll
|
2021-11-26 15:46:59 +08:00
|
|
|
(ell-ell). A following integer conversion corresponds to a \fIlong long\fP or
|
2021-05-05 17:07:40 +08:00
|
|
|
\fIunsigned long long\fP argument, or a following n conversion corresponds to
|
|
|
|
a pointer to a long long argument.
|
|
|
|
.TP
|
|
|
|
.B q
|
|
|
|
A synonym for \fBll\fP.
|
|
|
|
.TP
|
|
|
|
.B L
|
|
|
|
A following a, A, e, E, f, F, g, or G conversion corresponds to a long double
|
|
|
|
argument.
|
|
|
|
.TP
|
|
|
|
.B z
|
|
|
|
A following integer conversion corresponds to a \fIsize_t\fP or \fIssize_t\fP
|
|
|
|
argument.
|
|
|
|
.SH "Conversion specifiers"
|
|
|
|
A character that specifies the type of conversion to be applied. The
|
|
|
|
conversion specifiers and their meanings are:
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B d, i
|
2021-11-26 15:46:59 +08:00
|
|
|
The int argument is converted to signed decimal notation. The precision, if
|
2021-05-05 17:07:40 +08:00
|
|
|
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.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B o, u, x, X
|
|
|
|
The unsigned int argument is converted to unsigned octal (o), unsigned decimal
|
2021-11-26 15:46:59 +08:00
|
|
|
(u), or unsigned hexadecimal (\fBx\fP and \fBX\fP) notation. The letters
|
2022-09-21 05:30:19 +08:00
|
|
|
\fIabcdef\fP are used for \fBx\fP conversions; the letters \fIABCDEF\fP are
|
|
|
|
used for \fBX\fP 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.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B e, E
|
2022-09-21 05:30:19 +08:00
|
|
|
The double argument is rounded and output in the style \fB"[-]d.ddde±dd"\fP
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B f, F
|
2022-09-21 05:30:19 +08:00
|
|
|
The double argument is rounded and output to decimal notation in the style
|
|
|
|
\fB"[-]ddd.ddd"\fP.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B g, G
|
|
|
|
The double argument is converted in style f or e.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B c
|
|
|
|
The int argument is converted to an unsigned char, and the resulting character
|
|
|
|
is written.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B s
|
2022-09-21 05:30:19 +08:00
|
|
|
The \fIconst char *\fP 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 terminating null 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 terminating null byte.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B p
|
|
|
|
The \fIvoid *\fP pointer argument is printed in hexadecimal.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B n
|
|
|
|
The number of characters written so far is stored into the integer pointed to
|
|
|
|
by the corresponding argument.
|
2002-03-04 18:09:48 +08:00
|
|
|
.TP
|
2021-05-05 17:07:40 +08:00
|
|
|
.B %
|
|
|
|
A '%' is written. No argument is converted.
|
2021-10-25 14:54:08 +08:00
|
|
|
.SH EXAMPLE
|
|
|
|
.nf
|
2021-11-05 06:48:23 +08:00
|
|
|
mprintf("My name is %s\\n", name);
|
|
|
|
mprintf("Pi is almost %f\\n", 25/8);
|
2021-10-25 14:54:08 +08:00
|
|
|
.fi
|
2004-04-30 16:38:08 +08:00
|
|
|
.SH AVAILABILITY
|
2016-04-01 16:14:06 +08:00
|
|
|
These functions will be removed from the public libcurl API in the future. Do
|
2021-05-05 17:07:40 +08:00
|
|
|
not use them in new programs or projects.
|
2002-03-04 18:09:48 +08:00
|
|
|
.SH RETURN VALUE
|
|
|
|
The \fBcurl_maprintf\fP and \fBcurl_mvaprintf\fP functions return a pointer to
|
2008-12-29 05:56:56 +08:00
|
|
|
a newly allocated string, or NULL if it failed.
|
2002-03-04 18:09:48 +08:00
|
|
|
|
2021-07-07 20:51:17 +08:00
|
|
|
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.
|
2002-03-04 18:09:48 +08:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR printf "(3), " sprintf "(3), " fprintf "(3), " vprintf "(3) "
|