Commit | Line | Data |
---|---|---|
af359dea | 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
411867e7 | 2 | .\" All rights reserved. |
c3ce85c3 | 3 | .\" |
411867e7 | 4 | .\" This code is derived from software contributed to Berkeley by |
af359dea C |
5 | .\" Chris Torek and the American National Standards Committee X3, |
6 | .\" on Information Processing Systems. | |
411867e7 | 7 | .\" |
af359dea C |
8 | .\" Redistribution and use in source and binary forms, with or without |
9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | |
15 | .\" documentation and/or other materials provided with the distribution. | |
16 | .\" 3. All advertising materials mentioning features or use of this software | |
17 | .\" must display the following acknowledgement: | |
18 | .\" This product includes software developed by the University of | |
19 | .\" California, Berkeley and its contributors. | |
20 | .\" 4. Neither the name of the University nor the names of its contributors | |
21 | .\" may be used to endorse or promote products derived from this software | |
22 | .\" without specific prior written permission. | |
411867e7 | 23 | .\" |
af359dea C |
24 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | .\" SUCH DAMAGE. | |
411867e7 | 35 | .\" |
af359dea C |
36 | .\" @(#)printf.3 6.14 (Berkeley) 7/30/91 |
37 | .\" | |
38 | .Dd July 30, 1991 | |
39 | .Dt PRINTF 3 | |
40 | .Os | |
41 | .Sh NAME | |
42 | .Nm printf , | |
43 | .Nm fprintf , | |
44 | .Nm sprintf , | |
45 | .Nm snprintf , | |
46 | .Nm vprintf , | |
47 | .Nm vfprintf, | |
48 | .Nm vsprintf , | |
49 | .Nm vsnprintf | |
50 | .Nd formatted output conversion | |
51 | .Sh SYNOPSIS | |
52 | .Fd #include <stdio.h> | |
53 | .Ft int | |
54 | .Fn printf "const char *format" ... | |
55 | .Ft int | |
56 | .Fn fprintf "FILE *stream" "const char *format" ... | |
57 | .Ft int | |
58 | .Fn sprintf "char *str" "const char *format" ... | |
59 | .Ft int | |
60 | .Fn snprintf "char *str" "size_t size" "const char *format" ... | |
61 | .\" .Ft int | |
62 | .\" .Fn smprintf "const char *format" ... | |
63 | .Fd #include <stdarg.h> | |
64 | .Ft int | |
65 | .Fn vprintf "const char *format" "va_list ap" | |
66 | .Ft int | |
67 | .Fn vfprintf "FILE *stream" "const char *format" "va_list ap" | |
68 | .Ft int | |
69 | .Fn vsprintf "char *str" "char *format" "va_list ap" | |
70 | .Ft int | |
71 | .Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" | |
72 | .\" .Ft int | |
73 | .\" .Fn vsmprintf "const char *format" "va_list ap" | |
74 | .Sh DESCRIPTION | |
411867e7 | 75 | The |
af359dea | 76 | .Fn printf |
411867e7 | 77 | family of functions produces output according to a |
af359dea | 78 | .Fa format |
411867e7 | 79 | as described below. |
af359dea | 80 | .Fn Printf |
df27e01d | 81 | and |
af359dea C |
82 | .Fn vprintf |
83 | write output to | |
84 | .Em stdout, | |
85 | the standard output stream; | |
86 | .Fn fprintf | |
df27e01d | 87 | and |
af359dea C |
88 | .Fn vfprintf |
89 | write output to the given output | |
90 | .Fa stream ; | |
91 | .Fn sprintf , | |
92 | .Fn snprintf , | |
93 | .Fn vsprintf , | |
df27e01d | 94 | and |
af359dea | 95 | .Fn vsnprintf |
411867e7 | 96 | write to the character string |
af359dea | 97 | .Fa str . |
411867e7 KB |
98 | .\" .IR str ; |
99 | .\" and | |
100 | .\" .I smprintf | |
101 | .\" and | |
102 | .\" .I vsmprintf | |
103 | .\" dynamically allocate a new string with | |
104 | .\" .IR malloc . | |
af359dea C |
105 | These functions write the output under the control of a |
106 | .Fa format | |
107 | string that specifies how subsequent arguments | |
108 | (or arguments accessed via the variable-length argument facilities of | |
109 | .Xr stdarg 3 ) | |
110 | are converted for output. | |
411867e7 KB |
111 | .\" Except for |
112 | .\" .I smprintf | |
113 | .\" and | |
114 | .\" .IR vsmprintf , | |
115 | .\" all of these functions return | |
af359dea | 116 | These functions return |
411867e7 | 117 | the number of characters printed |
af359dea C |
118 | (not including the trailing |
119 | .Ql \e0 | |
120 | used to end output to strings). | |
411867e7 KB |
121 | .\" .I Smprintf |
122 | .\" and | |
123 | .\" .I vsmprintf | |
124 | .\" return a pointer to a string of an appropriate length; | |
125 | .\" this pointer should be passed to | |
126 | .\" .I free | |
127 | .\" to release the associated storage | |
128 | .\" when it is no longer needed. | |
129 | .\" If sufficient space is not avaliable, | |
130 | .\" .I smprintf | |
131 | .\" and | |
132 | .\" .I vsmprintf | |
133 | .\" will return | |
134 | .\" .SM | |
af359dea C |
135 | .\" .BR |
136 | .Fn Snprintf | |
a2f1db91 | 137 | and |
af359dea | 138 | .Fn vsnprintf |
411867e7 | 139 | will write at most |
af359dea | 140 | .Fa size Ns \-1 |
411867e7 KB |
141 | of the characters printed into the output string |
142 | (the | |
af359dea C |
143 | .Fa size Ns 'th |
144 | character then gets the terminating | |
145 | .Ql \e0 ) ; | |
411867e7 | 146 | if the return value is greater than or equal to the |
af359dea | 147 | .Fa size |
411867e7 KB |
148 | argument, the string was too short |
149 | and some of the printed characters were discarded. | |
af359dea | 150 | .Fn Sprintf |
df27e01d | 151 | and |
af359dea | 152 | .Fn vsprintf |
411867e7 | 153 | effectively assume an infinte |
af359dea C |
154 | .Fa size . |
155 | .Pp | |
156 | The format string is composed of zero or more directives: | |
157 | ordinary | |
158 | .\" multibyte | |
159 | characters (not | |
160 | .Cm % ) , | |
161 | which are copied unchanged to the output stream; | |
162 | and conversion specifications, each of which results | |
163 | in fetching zero or more subsequent arguments. | |
164 | Each conversion specification is introduced by | |
165 | the character | |
166 | .Cm % . | |
167 | The arguments must correspond properly (after type promotion) | |
411867e7 | 168 | with the conversion specifier. |
af359dea C |
169 | After the |
170 | .Cm % , | |
171 | the following appear in sequence: | |
172 | .Bl -bullet | |
173 | .It | |
a2f1db91 | 174 | Zero or more of the following flags: |
af359dea C |
175 | .Bl -hyphen -offset indent |
176 | .It | |
177 | a | |
178 | .Cm # | |
179 | character | |
ef8094b4 KM |
180 | specifying that the value should be converted to an ``alternate form''. |
181 | For | |
af359dea C |
182 | .Cm c , |
183 | .Cm d , | |
184 | .Cm i , | |
185 | .Cm n , | |
186 | .Cm p , | |
187 | .Cm s , | |
ef8094b4 | 188 | and |
af359dea | 189 | .Cm u , |
df27e01d KB |
190 | conversions, this option has no effect. |
191 | For | |
af359dea | 192 | .Cm o |
ef8094b4 | 193 | conversions, the precision of the number is increased to force the first |
df27e01d KB |
194 | character of the output string to a zero (except if a zero value is printed |
195 | with an explicit precision of zero). | |
196 | For | |
af359dea | 197 | .Cm x |
df27e01d | 198 | and |
af359dea | 199 | .Cm X |
df27e01d | 200 | conversions, a non-zero result has the string |
af359dea | 201 | .Ql 0x |
df27e01d | 202 | (or |
af359dea | 203 | .Ql 0X |
df27e01d | 204 | for |
af359dea | 205 | .Cm X |
df27e01d KB |
206 | conversions) prepended to it. |
207 | For | |
af359dea C |
208 | .Cm e , |
209 | .Cm E , | |
210 | .Cm f , | |
211 | .Cm g , | |
ef8094b4 | 212 | and |
af359dea | 213 | .Cm G , |
ef8094b4 | 214 | conversions, the result will always contain a decimal point, even if no |
df27e01d KB |
215 | digits follow it (normally, a decimal point appears in the results of |
216 | those conversions only if a digit follows). | |
217 | For | |
af359dea | 218 | .Cm g |
ef8094b4 | 219 | and |
af359dea | 220 | .Cm G |
ef8094b4 | 221 | conversions, trailing zeros are not removed from the result as they |
df27e01d | 222 | would otherwise be. |
af359dea C |
223 | .It |
224 | A zero | |
225 | .Sq Cm \&0 | |
226 | character specifying zero padding. | |
df27e01d | 227 | For all conversions except |
af359dea | 228 | .Cm n , |
df27e01d | 229 | the converted value is padded on the left with zeros rather than blanks. |
411867e7 | 230 | If a precision is given with a numeric conversion |
af359dea C |
231 | .Pf ( Mc d , |
232 | .Cm i , | |
233 | .Cm o , | |
234 | .Cm u , | |
235 | .Cm i , | |
236 | .Cm x , | |
df27e01d | 237 | and |
af359dea C |
238 | .Cm X ) , |
239 | the | |
240 | .Sq Cm \&0 | |
241 | flag is ignored. | |
242 | .It | |
243 | A negative field width flag | |
244 | .Sq Cm \- | |
245 | indicates the converted value is to be left adjusted on the field boundary. | |
df27e01d | 246 | Except for |
af359dea | 247 | .Cm n |
df27e01d KB |
248 | conversions, the converted value is padded on the right with blanks, |
249 | rather than on the left with blanks or zeros. | |
af359dea C |
250 | A |
251 | .Sq Cm \- | |
252 | overrides a | |
253 | .Sq Cm \&0 | |
254 | if both are given. | |
255 | .It | |
df27e01d | 256 | A space, specifying that a blank should be left before a positive number |
411867e7 | 257 | produced by a signed conversion |
af359dea C |
258 | .Pf ( Cm d , |
259 | .Cm e , | |
260 | .Cm E , | |
261 | .Cm f , | |
262 | .Cm g , | |
263 | .Cm G , | |
df27e01d | 264 | or |
af359dea C |
265 | .Cm i ) . |
266 | .It | |
267 | a | |
268 | .Sq Cm + | |
269 | character specifying that a sign always be placed before a | |
df27e01d | 270 | number produced by a signed conversion. |
af359dea C |
271 | A |
272 | .Sq Cm + | |
273 | overrides a space if both are used. | |
274 | .El | |
275 | .It | |
276 | An optional decimal digit string specifying a minimum field width. | |
df27e01d | 277 | If the converted value has fewer characters than the field width, it will |
af359dea C |
278 | be padded with spaces on the left (or right, if the left-adjustment |
279 | flag has been given) to fill out | |
280 | the field width. | |
281 | .It | |
282 | An optional precision, in the form of a period | |
283 | .Sq Cm \&. | |
284 | followed by an | |
df27e01d KB |
285 | optional digit string. If the digit string is omitted, the precision |
286 | is taken as zero. This gives the minimum number of digits to appear for | |
af359dea C |
287 | .Cm d , |
288 | .Cm i , | |
289 | .Cm o , | |
290 | .Cm u , | |
291 | .Cm x , | |
df27e01d | 292 | and |
af359dea C |
293 | .Cm X |
294 | conversions, the number of digits to appear after the decimal-point for | |
295 | .Cm e , | |
296 | .Cm E , | |
df27e01d | 297 | and |
af359dea | 298 | .Cm f |
df27e01d | 299 | conversions, the maximum number of significant digits for |
af359dea | 300 | .Cm g |
df27e01d | 301 | and |
af359dea | 302 | .Cm G |
df27e01d KB |
303 | conversions, or the maximum number of characters to be printed from a |
304 | string for | |
af359dea | 305 | .Cm s |
df27e01d | 306 | conversions. |
af359dea C |
307 | .It |
308 | The optional character | |
309 | .Cm h , | |
c3ce85c3 | 310 | specifying that a following |
af359dea C |
311 | .Cm d , |
312 | .Cm i , | |
313 | .Cm o , | |
314 | .Cm u , | |
315 | .Cm x , | |
c3ce85c3 | 316 | or |
af359dea | 317 | .Cm X |
df27e01d | 318 | conversion corresponds to a |
af359dea | 319 | .Em short int |
df27e01d | 320 | or |
af359dea | 321 | .Em unsigned short int |
df27e01d | 322 | argument, or that a following |
af359dea | 323 | .Cm n |
df27e01d | 324 | conversion corresponds to a pointer to a |
af359dea | 325 | .Em short int |
df27e01d | 326 | argument. |
af359dea C |
327 | .It |
328 | The optional character | |
329 | .Cm l | |
df27e01d | 330 | (ell) specifying that a following |
af359dea C |
331 | .Cm d , |
332 | .Cm i , | |
333 | .Cm o , | |
334 | .Cm u , | |
335 | .Cm x , | |
a2f1db91 | 336 | or |
af359dea C |
337 | .Cm X |
338 | conversion applies to a pointer to a | |
339 | .Em long int | |
df27e01d | 340 | or |
af359dea | 341 | .Em unsigned long int |
df27e01d | 342 | argument, or that a following |
af359dea | 343 | .Cm n |
df27e01d | 344 | conversion corresponds to a pointer to a |
af359dea | 345 | .Em long int |
df27e01d | 346 | argument. |
af359dea | 347 | .It |
df27e01d | 348 | The character |
af359dea | 349 | .Cm L |
df27e01d | 350 | specifying that a following |
af359dea C |
351 | .Cm e , |
352 | .Cm E , | |
353 | .Cm f , | |
354 | .Cm g , | |
df27e01d | 355 | or |
af359dea | 356 | .Cm G |
df27e01d | 357 | conversion corresponds to a |
af359dea | 358 | .Em long double |
df27e01d | 359 | argument (but note that long double values are not currently supported |
af359dea C |
360 | by the |
361 | .Tn VAX | |
362 | and | |
363 | .Tn Tahoe | |
364 | compilers). | |
365 | .It | |
366 | A character that specifies the type of conversion to be applied. | |
367 | .El | |
368 | .Pp | |
369 | A field width or precision, or both, may be indicated by | |
370 | an asterisk | |
371 | .Ql * | |
372 | instead of a | |
df27e01d | 373 | digit string. |
af359dea C |
374 | In this case, an |
375 | .Em int | |
376 | argument supplies the field width or precision. | |
df27e01d KB |
377 | A negative field width is treated as a left adjustment flag followed by a |
378 | positive field width; a negative precision is treated as though it were | |
379 | missing. | |
af359dea C |
380 | .Pp |
381 | The conversion specifiers and their meanings are: | |
382 | .Bl -tag -width "diouxX" | |
383 | .It Cm diouxX | |
df27e01d | 384 | The |
af359dea | 385 | .Em int |
df27e01d | 386 | (or appropriate variant) argument is converted to signed decimal |
af359dea C |
387 | .Pf ( Cm d |
388 | and | |
389 | .Cm i ) , | |
df27e01d | 390 | unsigned octal |
af359dea | 391 | .Pq Cm o , |
df27e01d | 392 | unsigned decimal |
af359dea | 393 | .Pq Cm u , |
df27e01d | 394 | or unsigned hexadecimal |
af359dea C |
395 | .Pf ( Cm x |
396 | and | |
397 | .Cm X ) | |
398 | notation. The letters | |
399 | .Cm abcdef | |
df27e01d | 400 | are used for |
af359dea | 401 | .Cm x |
df27e01d | 402 | conversions; the letters |
af359dea | 403 | .Cm ABCDEF |
df27e01d | 404 | are used for |
af359dea | 405 | .m X |
df27e01d KB |
406 | conversions. |
407 | The precision, if any, gives the minimum number of digits that must | |
408 | appear; if the converted value requires fewer digits, it is padded on | |
409 | the left with zeros. | |
af359dea | 410 | .It Cm DOU |
df27e01d | 411 | The |
af359dea | 412 | .Em long int |
df27e01d KB |
413 | argument is converted to signed decimal, unsigned octal, or unsigned |
414 | decimal, as if the format had been | |
af359dea C |
415 | .Cm ld , |
416 | .Cm lo , | |
df27e01d | 417 | or |
af359dea | 418 | .Cm lu |
df27e01d KB |
419 | respectively. |
420 | These conversion characters are deprecated, and will eventually disappear. | |
af359dea | 421 | .It Cm eE |
df27e01d | 422 | The |
af359dea | 423 | .Em double |
df27e01d | 424 | argument is rounded and converted in the style |
af359dea C |
425 | .Sm off |
426 | .Pf [\-]d Cm \&. No ddd Cm e No \\*(Pmdd | |
427 | .Sm on | |
428 | where there is one digit before the | |
429 | decimal-point character | |
430 | and the number of digits after it is equal to the precision; | |
431 | if the precision is missing, | |
432 | it is taken as 6; if the precision is | |
433 | zero, no decimal-point character appears. | |
df27e01d | 434 | An |
af359dea | 435 | .Cm E |
df27e01d | 436 | conversion uses the letter |
af359dea | 437 | .Cm E |
df27e01d | 438 | (rather than |
af359dea | 439 | .Cm e ) |
df27e01d KB |
440 | to introduce the exponent. |
441 | The exponent always contains at least two digits; if the value is zero, | |
442 | the exponent is 00. | |
af359dea | 443 | .It Cm f |
df27e01d | 444 | The |
af359dea | 445 | .Em double |
df27e01d | 446 | argument is rounded and converted to decimal notation in the style |
af359dea C |
447 | .Sm off |
448 | .Pf [-]ddd Cm \&. No ddd , | |
449 | .Sm on | |
450 | where the number of digits after the decimal-point character | |
451 | is equal to the precision specification. | |
452 | If the precision is missing, it is taken as 6; if the precision is | |
453 | explicitly zero, no decimal-point character appears. | |
df27e01d | 454 | If a decimal point appears, at least one digit appears before it. |
af359dea | 455 | .It Cm g |
df27e01d | 456 | The |
af359dea C |
457 | .Em double |
458 | argument is converted in style | |
459 | .Cm f | |
df27e01d | 460 | or |
af359dea | 461 | .Cm e |
df27e01d | 462 | (or |
af359dea | 463 | .Cm E |
df27e01d | 464 | for |
af359dea | 465 | .Cm G |
df27e01d KB |
466 | conversions). |
467 | The precision specifies the number of significant digits. | |
468 | If the precision is missing, 6 digits are given; if the precision is zero, | |
469 | it is treated as 1. | |
470 | Style | |
af359dea | 471 | .Cm e |
df27e01d KB |
472 | is used if the exponent from its conversion is less than -4 or greater than |
473 | or equal to the precision. | |
474 | Trailing zeros are removed from the fractional part of the result; a | |
475 | decimal point appears only if it is followed by at least one digit. | |
af359dea | 476 | .It Cm c |
df27e01d | 477 | The |
af359dea | 478 | .Em int |
df27e01d | 479 | argument is converted to an |
af359dea C |
480 | .Em unsigned char , |
481 | and the resulting character is written. | |
482 | .It Cm s | |
df27e01d | 483 | The |
af359dea C |
484 | .Dq Em char * |
485 | argument is expected to be a pointer to an array of character type (pointer | |
486 | to a string). | |
487 | Characters from the array are written up to (but not including) | |
488 | a terminating | |
489 | .Dv NUL | |
490 | character; | |
491 | if a precision is specified, no more than the number specified are | |
492 | written. | |
493 | If a precision is given, no null character | |
494 | need be present; if the precision is not specified, or is greater than | |
495 | the size of the array, the array must contain a terminating | |
496 | .Dv NUL | |
497 | character. | |
498 | .It Cm p | |
df27e01d | 499 | The |
af359dea C |
500 | .Dq Em void * |
501 | pointer argument is printed in hexadecimal (as if by | |
502 | .Ql %#x | |
503 | or | |
504 | .Ql %#lx ) . | |
505 | .It Cm n | |
df27e01d KB |
506 | The number of characters written so far is stored into the |
507 | integer indicated by the | |
af359dea | 508 | .Dq Em int * |
df27e01d KB |
509 | (or variant) pointer argument. |
510 | No argument is converted. | |
af359dea C |
511 | .It Cm % |
512 | A | |
513 | .Ql % | |
514 | is written. No argument is converted. The complete conversion specification | |
515 | is | |
516 | .Ql %% . | |
517 | .El | |
518 | .Pp | |
df27e01d KB |
519 | In no case does a non-existent or small field width cause truncation of |
520 | a field; if the result of a conversion is wider than the field width, the | |
af359dea C |
521 | field is expanded to contain the conversion result. |
522 | .Pp | |
523 | .Sh EXAMPLES | |
c3ce85c3 KM |
524 | .br |
525 | To print a date and time in the form `Sunday, July 3, 10:02', | |
526 | where | |
af359dea | 527 | .Em weekday |
c3ce85c3 | 528 | and |
af359dea C |
529 | .Em month |
530 | are pointers to strings: | |
531 | .Bd -literal -offset indent | |
532 | #include <stdio.h> | |
533 | fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", | |
534 | weekday, month, day, hour, min); | |
535 | .Ed | |
536 | .Pp | |
537 | To print \*(Pi | |
538 | to five decimal places: | |
539 | .Bd -literal -offset indent | |
540 | #include <math.h> | |
541 | #include <stdio.h> | |
542 | fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0)); | |
543 | .Ed | |
544 | .Pp | |
df27e01d | 545 | To allocate a 128 byte string and print into it: |
af359dea | 546 | .Bd -literal -offset indent |
df27e01d | 547 | #include <stdio.h> |
af359dea C |
548 | #include <stdlib.h> |
549 | #include <stdarg.h> | |
550 | char *newfmt(const char *fmt, ...) | |
df27e01d | 551 | { |
af359dea C |
552 | char *p; |
553 | va_list ap; | |
554 | if ((p = malloc(128)) == NULL) | |
555 | return (NULL); | |
556 | va_start(ap, fmt); | |
557 | (void) vsnprintf(p, 128, fmt, ap); | |
558 | va_end(ap); | |
559 | return (p); | |
df27e01d | 560 | } |
af359dea C |
561 | .Ed |
562 | .Sh SEE ALSO | |
563 | .Xr printf 1 , | |
564 | .Xr scanf 3 | |
565 | .Sh STANDARDS | |
566 | The | |
567 | .Fn fprintf , | |
568 | .Fn printf , | |
569 | .Fn sprintf , | |
570 | .Fn vprintf , | |
571 | .Fn vfprintf , | |
572 | and | |
573 | .Fn vsprintf | |
574 | functions | |
575 | conform to | |
576 | .St -ansiC . | |
577 | .Sh HISTORY | |
578 | The functions | |
579 | .Fn snprintf | |
580 | and | |
581 | .Fn vsnprintf | |
582 | are new to this release. | |
583 | .Sh BUGS | |
584 | The conversion formats | |
585 | .Cm \&%D , | |
586 | .Cm \&%O , | |
587 | and | |
588 | .Cm %U | |
589 | are not standard and | |
df27e01d | 590 | are provided only for backward compatibility. |
af359dea C |
591 | The effect of padding the |
592 | .Cm %p | |
593 | format with zeros (either by the | |
594 | .Sq Cm 0 | |
df27e01d | 595 | flag or by specifying a precision), and the benign effect (i.e., none) |
af359dea C |
596 | of the |
597 | .Sq Cm # | |
598 | flag on | |
599 | .Cm %n | |
600 | and | |
601 | .Cm %p | |
602 | conversions, as well as other | |
603 | nonsensical combinations such as | |
604 | .Cm %Ld , | |
605 | are not standard; such combinations | |
df27e01d | 606 | should be avoided. |
af359dea | 607 | .Pp |
411867e7 | 608 | Because |
af359dea | 609 | .Fn sprintf |
411867e7 | 610 | and |
af359dea | 611 | .Fn vsprintf |
411867e7 KB |
612 | assume an infinitely long string, |
613 | callers must be careful not to overflow the actual space; | |
614 | this is often impossible to assure. | |
615 | For safety, programmers should use the | |
af359dea | 616 | .Fn snprintf |
411867e7 KB |
617 | interface instead. |
618 | Unfortunately, this interface is not portable. |