2
0

curl_mprintf.3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 "30 April 2004" "libcurl" "libcurl"
  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. \fIva_list\fP instead of a variable number of arguments. These functions do
  63. not call the \fIva_end\fP macro. Because they invoke the \fIva_arg\fP macro,
  64. the value of \fIap\fP 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. .nf
  88. curl_mprintf("%*d", width, num);
  89. .fi
  90. and
  91. .nf
  92. curl_mprintf("%2$*1$d", width, num);
  93. .fi
  94. are equivalent. The second style allows repeated references to the same
  95. argument.
  96. If the style using '$' is used, it must be used throughout for all conversions
  97. taking an argument and all width and precision arguments, but it may be mixed
  98. with "%%" formats, which do not consume an argument. There may be no gaps in
  99. the numbers of arguments specified using '$'; for example, if arguments 1 and
  100. 3 are specified, argument 2 must also be specified somewhere in the format
  101. string.
  102. .SH "Flag characters"
  103. The character % is followed by zero or more of the following flags:
  104. .TP
  105. .B #
  106. The value should be converted to its "alternate form".
  107. .TP
  108. .B 0
  109. The value should be zero padded.
  110. .TP
  111. .B -
  112. The converted value is to be left adjusted on the field boundary. (The
  113. default is right justification.) The converted value is padded on the right
  114. with blanks, rather than on the left with blanks or zeros. A '-' overrides a
  115. \&'0' if both are given.
  116. .TP
  117. .B ' '
  118. (a space) A blank should be left before a positive number (or empty string)
  119. produced by a signed conversion.
  120. .TP
  121. .B +
  122. A sign (+ or -) should always be placed before a number produced by a signed
  123. conversion. By default, a sign is used only for negative numbers. A '+'
  124. overrides a space if both are used.
  125. .SH "Field width"
  126. An optional decimal digit string (with nonzero first digit) specifying a
  127. minimum field width. If the converted value has fewer characters than the
  128. field width, it will be padded with spaces on the left (or right, if the
  129. left-adjustment flag has been given). Instead of a decimal digit string one
  130. may write "*" or "*m$" (for some decimal integer m) to specify that the field
  131. width is given in the next argument, or in the \fIm-th\fP argument,
  132. respectively, which must be of type int. A negative field width is taken as
  133. a '-' flag followed by a positive field width. In no case does a nonexistent
  134. or small field width cause truncation of a field; if the result of a
  135. conversion is wider than the field width, the field is expanded to contain the
  136. conversion result.
  137. .SH "Precision"
  138. An optional precision in the form of a period ('.') followed by an optional
  139. decimal digit string. Instead of a decimal digit string one may write "*" or
  140. "*m$" (for some decimal integer m) to specify that the precision is given in
  141. the next argument, or in the \fIm-th\fP argument, respectively, which must be of
  142. type int. If the precision is given as just '.', the precision is taken to be
  143. zero. A negative precision is taken as if the precision were omitted. This
  144. gives the minimum number of digits to appear for \fBd\fP, \fBi\fP, \fBo\fP,
  145. \fBu\fP, \fBx\fP, and \fBX\fP conversions, the number of digits to appear
  146. after the radix character for \fBa\fP, \fBA\fP, \fBe\fP, \fBE\fP, \fBf\fP, and
  147. \fBF\fP conversions, the maximum number of significant digits for \fBg\fP and
  148. \fBG\fP conversions, or the maximum number of characters to be printed from a
  149. string for \fBs\fP and \fBS\fP conversions.
  150. .SH "Length modifier"
  151. .TP
  152. .B h
  153. A following integer conversion corresponds to a \fIshort\fP or \fIunsigned
  154. short\fP argument.
  155. .TP
  156. .B l
  157. (ell) A following integer conversion corresponds to a \fIlong\fP or
  158. \fIunsigned long\fP argument, or a following n conversion corresponds to a
  159. pointer to a long argument
  160. .TP
  161. .B ll
  162. (ell-ell). A following integer conversion corresponds to a \fIlong long\fP or
  163. \fIunsigned long long\fP argument, or a following n conversion corresponds to
  164. a pointer to a long long argument.
  165. .TP
  166. .B q
  167. A synonym for \fBll\fP.
  168. .TP
  169. .B L
  170. A following a, A, e, E, f, F, g, or G conversion corresponds to a long double
  171. argument.
  172. .TP
  173. .B z
  174. A following integer conversion corresponds to a \fIsize_t\fP or \fIssize_t\fP
  175. argument.
  176. .SH "Conversion specifiers"
  177. A character that specifies the type of conversion to be applied. The
  178. conversion specifiers and their meanings are:
  179. .TP
  180. .B d, i
  181. The int argument is converted to signed decimal notation. The precision, if
  182. any, gives the minimum number of digits that must appear; if the converted
  183. value requires fewer digits, it is padded on the left with zeros. The default
  184. precision is 1. When 0 is printed with an explicit precision 0, the output is
  185. empty.
  186. .TP
  187. .B o, u, x, X
  188. The unsigned int argument is converted to unsigned octal (o), unsigned decimal
  189. (u), or unsigned hexadecimal (\fBx\fP and \fBX\fP) notation. The letters
  190. \fIabcdef\fP are used for \fBx\fP conversions; the letters \fIABCDEF\fP are
  191. used for \fBX\fP conversions. The precision, if any, gives the minimum number
  192. of digits that must appear; if the converted value requires fewer digits, it
  193. is padded on the left with zeros. The default precision is 1. When 0 is
  194. printed with an explicit precision 0, the output is empty.
  195. .TP
  196. .B e, E
  197. The double argument is rounded and output in the style \fB"[-]d.ddde±dd"\fP
  198. .TP
  199. .B f, F
  200. The double argument is rounded and output to decimal notation in the style
  201. \fB"[-]ddd.ddd"\fP.
  202. .TP
  203. .B g, G
  204. The double argument is converted in style f or e.
  205. .TP
  206. .B c
  207. The int argument is converted to an unsigned char, and the resulting character
  208. is written.
  209. .TP
  210. .B s
  211. The \fIconst char *\fP argument is expected to be a pointer to an array of
  212. character type (pointer to a string). Characters from the array are written up
  213. to (but not including) a terminating null byte. If a precision is specified,
  214. no more than the number specified are written. If a precision is given, no
  215. null byte need be present; if the precision is not specified, or is greater
  216. than the size of the array, the array must contain a terminating null byte.
  217. .TP
  218. .B p
  219. The \fIvoid *\fP pointer argument is printed in hexadecimal.
  220. .TP
  221. .B n
  222. The number of characters written so far is stored into the integer pointed to
  223. by the corresponding argument.
  224. .TP
  225. .B %
  226. A '%' is written. No argument is converted.
  227. .SH EXAMPLE
  228. .nf
  229. curl_mprintf("My name is %s\\n", name);
  230. curl_mprintf("Pi is almost %f\\n", 25/8);
  231. .fi
  232. .SH AVAILABILITY
  233. These functions will be removed from the public libcurl API in the future. Do
  234. not use them in new programs or projects.
  235. .SH RETURN VALUE
  236. The \fBcurl_maprintf\fP and \fBcurl_mvaprintf\fP functions return a pointer to
  237. a newly allocated string, or NULL if it failed.
  238. All other functions return the number of characters actually printed
  239. (excluding the null byte used to end output to strings). Note that this
  240. sometimes differ from how the POSIX versions of these functions work.
  241. .SH "SEE ALSO"
  242. .BR printf "(3), " sprintf "(3), " fprintf "(3), " vprintf "(3) "