curl_mprintf.3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, Daniel Stenberg, <[email protected]>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .TH curl_printf 3 "May 17, 2022" "libcurl 7.85.0" "libcurl Manual"
  25. .SH NAME
  26. curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf
  27. curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf,
  28. curl_mvsprintf - formatted output conversion
  29. .SH SYNOPSIS
  30. .nf
  31. #include <curl/mprintf.h>
  32. int curl_mprintf(const char *format, ...);
  33. int curl_mfprintf(FILE *fd, const char *format, ...);
  34. int curl_msprintf(char *buffer, const char *format, ...);
  35. int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...);
  36. int curl_mvprintf(const char *format, va_list args);
  37. int curl_mvfprintf(FILE *fd, const char *format, va_list args);
  38. int curl_mvsprintf(char *buffer, const char *format, va_list args);
  39. int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
  40. va_list args);
  41. char *curl_maprintf(const char *format , ...);
  42. char *curl_mvaprintf(const char *format, va_list args);
  43. .fi
  44. .SH DESCRIPTION
  45. These functions produce output according to the format string and given
  46. arguments. They are mostly clones of the well-known C-style functions but
  47. there are slight differences in behavior.
  48. We discourage users from using any of these functions in new applications.
  49. Functions in the curl_mprintf() family produce output according to a format as
  50. described below. The functions \fBcurl_mprintf()\fP and \fBcurl_mvprintf()\fP
  51. write output to stdout, the standard output stream; \fBcurl_mfprintf()\fP and
  52. \fBcurl_mvfprintf()\fP write output to the given output stream;
  53. \fBcurl_msprintf()\fP, \fBcurl_msnprintf()\fP, \fBcurl_mvsprintf()\fP, and
  54. \fBcurl_mvsnprintf()\fP write to the character string \fBbuffer\fP.
  55. The functions \fBcurl_msnprintf()\fP and \fBcurl_mvsnprintf()\fP write at most
  56. \fImaxlength\fP bytes (including the terminating null byte ('\\0')) to
  57. \fIbuffer\fP.
  58. The functions \fBcurl_mvprintf()\fP, \fBcurl_mvfprintf()\fP,
  59. \fBcurl_mvsprintf()\fP, \fBcurl_mvsnprintf()\fP are equivalent to the
  60. functions \fBcurl_mprintf()\fP, \fBcurl_mfprintf()\fP, \fBcurl_msprintf()\fP,
  61. \fBcurl_msnprintf()\fP, respectively, except that they are called with a
  62. va_list instead of a variable number of arguments. These functions do not
  63. call the va_end macro. Because they invoke the va_arg macro, the value of ap
  64. is undefined after the call.
  65. The functions \fBcurl_maprintf()\fP and \fBcurl_mvaprintf()\fP return the
  66. output string as pointer to a newly allocated memory area. The returned string
  67. must be \fIcurl_free(3)\fPed by the receiver.
  68. All of these functions write the output under the control of a format string
  69. that specifies how subsequent arguments are converted for output.
  70. .SH FORMAT STRING
  71. The format string is composed of zero or more directives: ordinary characters
  72. (not %), which are copied unchanged to the output stream; and conversion
  73. specifications, each of which results in fetching zero or more subsequent
  74. arguments. Each conversion specification is introduced by the character %, and
  75. ends with a conversion specifier. In between there may be (in this order) zero
  76. or more \fIflags\fP, an optional minimum \fIfield width\fP, an optional
  77. \fIprecision\fP and an optional \fIlength modifier\fP.
  78. .SH "The $ modifier"
  79. The arguments must correspond properly with the conversion specifier. By
  80. default, the arguments are used in the order given, where each '*' (see Field
  81. width and Precision below) and each conversion specifier asks for the next
  82. argument (and it is an error if insufficiently many arguments are given). One
  83. can also specify explicitly which argument is taken, at each place where an
  84. argument is required, by writing "%m$" instead of '%' and "*m$" instead
  85. of '*', where the decimal integer m denotes the position in the argument list
  86. of the desired argument, indexed starting from 1. Thus,
  87. curl_mprintf("%*d", width, num);
  88. and
  89. curl_mprintf("%2$*1$d", width, num);
  90. are equivalent. The second style allows repeated references to the same
  91. argument.
  92. If the style using '$' is used, it must be used throughout for all conversions
  93. taking an argument and all width and precision arguments, but it may be mixed
  94. with "%%" formats, which do not consume an argument. There may be no gaps in
  95. the numbers of argu‐ ments specified using '$'; for example, if arguments 1
  96. and 3 are specified, argument 2 must also be specified somewhere in the format
  97. string.
  98. .SH "Flag characters"
  99. The character % is followed by zero or more of the following flags:
  100. .TP
  101. .B #
  102. The value should be converted to its "alternate form".
  103. .TP
  104. .B 0
  105. The value should be zero padded.
  106. .TP
  107. .B -
  108. The converted value is to be left adjusted on the field boundary. (The
  109. default is right justification.) The converted value is padded on the right
  110. with blanks, rather than on the left with blanks or zeros. A '-' overrides a
  111. \&'0' if both are given.
  112. .TP
  113. .B ' '
  114. (a space) A blank should be left before a positive number (or empty string)
  115. produced by a signed conversion.
  116. .TP
  117. .B +
  118. A sign (+ or -) should always be placed before a number produced by a signed
  119. conversion. By default, a sign is used only for negative numbers. A '+'
  120. overrides a space if both are used.
  121. .SH "Field width"
  122. An optional decimal digit string (with nonzero first digit) specifying a
  123. minimum field width. If the converted value has fewer characters than the
  124. field width, it will be padded with spaces on the left (or right, if the
  125. left-adjustment flag has been given). Instead of a decimal digit string one
  126. may write "*" or "*m$" (for some decimal integer m) to specify that the field
  127. width is given in the next argument, or in the m-th argument, respec‐ tively,
  128. which must be of type int. A negative field width is taken as a '-' flag
  129. followed by a positive field width. In no case does a nonexistent or small
  130. field width cause truncation of a field; if the result of a conversion is
  131. wider than the field width, the field is expanded to contain the conversion
  132. result.
  133. .SH "Precision"
  134. An optional precision in the form of a period ('.') followed by an optional
  135. decimal digit string. Instead of a decimal digit string one may write "*" or
  136. "*m$" (for some decimal integer m) to specify that the precision is given in
  137. the next argument, or in the m-th argument, respectively, which must be of
  138. type int. If the precision is given as just '.', the precision is taken to be
  139. zero. A negative precision is taken as if the precision were omitted. This
  140. gives the minimum number of digits to appear for \fBd\fP, \fBi\fP, \fBo\fP,
  141. \fBu\fP, \fBx\fP, and \fBX\fP conversions, the number of digits to appear
  142. after the radix character for \fBa\fP, \fBA\fP, \fBe\fP, \fBE\fP, \fBf\fP, and
  143. \fBF\fP conversions, the maximum number of significant digits for \fBg\fP and
  144. \fBG\fP conversions, or the maximum number of characters to be printed from a
  145. string for \fBs\fP and \fBS\fP conversions.
  146. .SH "Length modifier"
  147. .TP
  148. .B h
  149. A following integer conversion corresponds to a \fIshort\fP or \fIunsigned
  150. short\fP argument.
  151. .TP
  152. .B l
  153. (ell) A following integer conversion corresponds to a \fIlong\fP or
  154. \fIunsigned long\fP argument, or a following n conversion corresponds to a
  155. pointer to a long argument
  156. .TP
  157. .B ll
  158. (ell-ell). A following integer conversion corresponds to a \fIlong long\fP or
  159. \fIunsigned long long\fP argument, or a following n conversion corresponds to
  160. a pointer to a long long argument.
  161. .TP
  162. .B q
  163. A synonym for \fBll\fP.
  164. .TP
  165. .B L
  166. A following a, A, e, E, f, F, g, or G conversion corresponds to a long double
  167. argument.
  168. .TP
  169. .B z
  170. A following integer conversion corresponds to a \fIsize_t\fP or \fIssize_t\fP
  171. argument.
  172. .SH "Conversion specifiers"
  173. A character that specifies the type of conversion to be applied. The
  174. conversion specifiers and their meanings are:
  175. .TP
  176. .B d, i
  177. The int argument is converted to signed decimal notation. The precision, if
  178. any, gives the minimum number of digits that must appear; if the converted
  179. value requires fewer digits, it is padded on the left with zeros. The default
  180. precision is 1. When 0 is printed with an explicit precision 0, the output is
  181. empty.
  182. .TP
  183. .B o, u, x, X
  184. The unsigned int argument is converted to unsigned octal (o), unsigned decimal
  185. (u), or unsigned hexadecimal (\fBx\fP and \fBX\fP) notation. The letters
  186. abcdef are used for \fBx\fP conversions; the letters ABCDEF are used for
  187. \fBX\fP conversions. The precision, if any, gives the minimum number of digits
  188. that must appear; if the converted value requires fewer digits, it is padded
  189. on the left with zeros. The default precision is 1. When 0 is printed with
  190. an explicit precision 0, the output is empty.
  191. .TP
  192. .B e, E
  193. The double argument is rounded and output in the style "[-]d.ddde±dd"
  194. .TP
  195. .B f, F
  196. The double argument is rounded and output to decimal notiation in the style
  197. [-]ddd.ddd.
  198. .TP
  199. .B g, G
  200. The double argument is converted in style f or e.
  201. .TP
  202. .B c
  203. The int argument is converted to an unsigned char, and the resulting character
  204. is written.
  205. .TP
  206. .B s
  207. The const char * argument is expected to be a pointer to an array of character
  208. type (pointer to a string). Characters from the array are written up to (but
  209. not including) a terminating null byte. If a precision is specified, no more
  210. than the number specified are written. If a precision is given, no null byte
  211. need be present; if the precision is not specified, or is greater than the
  212. size of the array, the array must contain a terminating null byte.
  213. .TP
  214. .B p
  215. The \fIvoid *\fP pointer argument is printed in hexadecimal.
  216. .TP
  217. .B n
  218. The number of characters written so far is stored into the integer pointed to
  219. by the corresponding argument.
  220. .TP
  221. .B %
  222. A '%' is written. No argument is converted.
  223. .SH EXAMPLE
  224. .nf
  225. mprintf("My name is %s\\n", name);
  226. mprintf("Pi is almost %f\\n", 25/8);
  227. .fi
  228. .SH AVAILABILITY
  229. These functions will be removed from the public libcurl API in the future. Do
  230. not use them in new programs or projects.
  231. .SH RETURN VALUE
  232. The \fBcurl_maprintf\fP and \fBcurl_mvaprintf\fP functions return a pointer to
  233. a newly allocated string, or NULL if it failed.
  234. All other functions return the number of characters actually printed
  235. (excluding the null byte used to end output to strings). Note that this
  236. sometimes differ from how the POSIX versions of these functions work.
  237. .SH "SEE ALSO"
  238. .BR printf "(3), " sprintf "(3), " fprintf "(3), " vprintf "(3) "