curl_printf(3)
π curl_printf β formatted output conversion π
bestie. sit down. we're doing curl_printf(3) from the Library Functions Manual, and it's the whole <curl/mprintf.h> girlie squad: curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf, curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf, curl_mvsprintf. ten functions, one very specific job. no cap.
β¨ NAME β¨
curl_maprintf</p>, curl_mfprintf</p>, curl_mprintf</p>, curl_msnprintf</p>, curl_msprintf</p>, curl_mvaprintf</p>, curl_mvfprintf</p>, curl_mvprintf</p>, curl_mvsnprintf</p>, curl_mvsprintf</p> β formatted output conversion π«Ά
π SYNOPSIS π
#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 πΈ
okay so these functions produce output according to the format string and the arguments you hand them. they're mostly clones of the well-known C-style functions β the ones you already know and love β but there are slight differences in behavior. read the fine print, bestie.
we discourage users from using any of these functions in new applications. π periodt, that's just what it says. it's giving legacy.
functions in the curl_mprintf() family produce output according to a format as described below (scroll down boo). here's the who-goes-where:
curl_mprintf()andcurl_mvprintf()write output tostdout, the standard output stream πcurl_mfprintf()andcurl_mvfprintf()write to the given output streamcurl_msprintf(),curl_msnprintf(),curl_mvsprintf(), andcurl_mvsnprintf()write to the character string buffer
the functions curl_msnprintf() and curl_mvsnprintf() write at most maxlength bytes (including the terminating null byte ('0')) to buffer. π
the functions curl_mvprintf(), curl_mvfprintf(), curl_mvsprintf(), curl_mvsnprintf() are equivalent to curl_mprintf(), curl_mfprintf(), curl_msprintf(), curl_msnprintf(), respectively β the ONLY glow-up is that they're called with a va_list instead of a variable number of arguments. important: these functions do not call the va_end macro. and 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 a pointer to a newly allocated memory area. the returned string may not be overwritten and must be curl_free(3)ed by the receiver. yes, that's on you. π
all of these functions write the output under the control of a format string that specifies how subsequent arguments are converted for output. iconic behavior honestly.
π¦ FORMAT STRING π¦
the format string is composed of zero or more directives, bestie:
- ordinary characters (not
%), which are copied unchanged to the output stream π - 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. order matters, don't freestyle it. β¨
π 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 π¨).
but you 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. so:
curl_mprintf("%*d", width, num);
and
curl_mprintf("%2$*1$d", width, num);
are equivalent. the second style allows repeated references to the same argument β very reuse, very mindful. π§
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. no skipping numbers, that's the rule. π
π 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 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. no clipping, only growth. π±
π 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, andXconversions - the number of digits to appear after the radix character for
a,A,e,E,f, andFconversions - the maximum number of significant digits for
gandGconversions - the maximum number of characters to be printed from a string for
sandSconversions
π Length modifier π
hβ a following integer conversion corresponds to ashortorunsigned shortargument.lβ (ell) a following integer conversion corresponds to alongorunsigned longargument, or a followingnconversion corresponds to a pointer to alongargumentllβ (ell-ell). a following integer conversion corresponds to along longorunsigned long longargument, or a followingnconversion corresponds to a pointer to along longargument.qβ a synonym forll.Lβ a followinga,A,e,E,f,F,g, orGconversion corresponds to along doubleargument.zβ a following integer conversion corresponds to asize_torssize_targument.
π Conversion specifiers π
a character that specifies the type of conversion to be applied. the conversion specifiers and their meanings are:
d,iβ theintargument 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 is1. when0is printed with an explicit precision0, the output is empty.o,u,x,Xβ theunsigned intargument is converted to unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal (xandX) notation. the lettersabcdefare used forxconversions; the lettersABCDEFare used forXconversions. 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 is1. when0is printed with an explicit precision0, the output is empty.e,Eβ thedoubleargument is rounded and output in the style"[-]d.ddde{+|-}dd"f,Fβ thedoubleargument is rounded and output to decimal notation in the style"[-]ddd.ddd".g,Gβ thedoubleargument is converted in stylefore.cβ theintargument is converted to anunsigned char, and the resulting character is written.sβ theconst 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 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. β οΈpβ thevoid *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 π
this functionality affects all supported protocols. every single one. slay. π
π§ EXAMPLE π§
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 β³
added in curl 7.1. a true elder. π΅β¨
π₯ 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. yes really, don't assume, bestie.
π«Ά SEE ALSO π«Ά
and that's the whole page, no crumbs left. πΈ this was curl_printf(3) straight out of libcurl, dated 2026-10-16 β xoxo, go forth and format responsibly, mwah π
π¦ where this page comes from
- ubuntu stonking: libcurl4-doc 8.20.0-2ubuntu11.1 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms