1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek and the American National Standards Committee X3, 6.\" on Information Processing Systems. 7.\" 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.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)printf.3 8.1 (Berkeley) 6/4/93 33.\" $FreeBSD: src/lib/libc/stdio/printf.3,v 1.63 2009/03/04 03:38:51 das Exp $ 34.\" $DragonFly: src/lib/libc/stdio/printf.3,v 1.6 2006/08/26 10:27:55 swildner Exp $ 35.\" 36.Dd March 3, 2009 37.Dt PRINTF 3 38.Os 39.Sh NAME 40.Nm printf , 41.Nm fprintf , 42.Nm sprintf , 43.Nm snprintf , 44.Nm asprintf , 45.Nm dprintf , 46.Nm vprintf , 47.Nm vfprintf , 48.Nm vsprintf , 49.Nm vsnprintf , 50.Nm vasprintf , 51.Nm vdprintf 52.Nd formatted output conversion 53.Sh LIBRARY 54.Lb libc 55.Sh SYNOPSIS 56.Fd "#define _WITH_DPRINTF" 57.In stdio.h 58.Ft int 59.Fn printf "const char * restrict format" ... 60.Ft int 61.Fn fprintf "FILE * restrict stream" "const char * restrict format" ... 62.Ft int 63.Fn sprintf "char * restrict str" "const char * restrict format" ... 64.Ft int 65.Fn snprintf "char * restrict str" "size_t size" "const char * restrict format" ... 66.Ft int 67.Fn asprintf "char **ret" "const char *format" ... 68.Ft int 69.Fn dprintf "int" "const char * restrict format" ... 70.In stdarg.h 71.Ft int 72.Fn vprintf "const char * restrict format" "va_list ap" 73.Ft int 74.Fn vfprintf "FILE * restrict stream" "const char * restrict format" "va_list ap" 75.Ft int 76.Fn vsprintf "char * restrict str" "const char * restrict format" "va_list ap" 77.Ft int 78.Fn vsnprintf "char * restrict str" "size_t size" "const char * restrict format" "va_list ap" 79.Ft int 80.Fn vasprintf "char **ret" "const char *format" "va_list ap" 81.Ft int 82.Fn vdprintf "int fd" "const char * restrict format" "va_list ap" 83.Sh DESCRIPTION 84The 85.Fn printf 86family of functions produces output according to a 87.Fa format 88as described below. 89The 90.Fn printf 91and 92.Fn vprintf 93functions 94write output to 95.Dv stdout , 96the standard output stream; 97.Fn fprintf 98and 99.Fn vfprintf 100write output to the given output 101.Fa stream ; 102.Fn dprintf 103and 104.Fn vdprintf 105write output to the given file descriptor; 106.Fn sprintf , 107.Fn snprintf , 108.Fn vsprintf , 109and 110.Fn vsnprintf 111write to the character string 112.Fa str ; 113and 114.Fn asprintf 115and 116.Fn vasprintf 117dynamically allocate a new string with 118.Xr malloc 3 . 119.Pp 120These functions write the output under the control of a 121.Fa format 122string that specifies how subsequent arguments 123(or arguments accessed via the variable-length argument facilities of 124.Xr stdarg 3 ) 125are converted for output. 126.Pp 127These functions return the number of characters printed 128(not including the trailing 129.Ql \e0 130used to end output to strings) or a negative value if an output error occurs, 131except for 132.Fn snprintf 133and 134.Fn vsnprintf , 135which return the number of characters that would have been printed if the 136.Fa size 137were unlimited 138(again, not including the final 139.Ql \e0 ) . 140.Pp 141The 142.Fn asprintf 143and 144.Fn vasprintf 145functions 146set 147.Fa *ret 148to be a pointer to a buffer sufficiently large to hold the formatted string. 149This pointer should be passed to 150.Xr free 3 151to release the allocated storage when it is no longer needed. 152If sufficient space cannot be allocated, 153.Fn asprintf 154and 155.Fn vasprintf 156will return \-1 and set 157.Fa ret 158to be a 159.Dv NULL 160pointer. 161.Pp 162The 163.Fn snprintf 164and 165.Fn vsnprintf 166functions 167will write at most 168.Fa size Ns \-1 169of the characters printed into the output string 170(the 171.Fa size Ns 'th 172character then gets the terminating 173.Ql \e0 ) ; 174if the return value is greater than or equal to the 175.Fa size 176argument, the string was too short 177and some of the printed characters were discarded. 178The output is always null-terminated. 179.Pp 180The 181.Fn sprintf 182and 183.Fn vsprintf 184functions 185effectively assume an infinite 186.Fa size . 187.Pp 188The format string is composed of zero or more directives: 189ordinary 190.\" multibyte 191characters (not 192.Cm % ) , 193which are copied unchanged to the output stream; 194and conversion specifications, each of which results 195in fetching zero or more subsequent arguments. 196Each conversion specification is introduced by 197the 198.Cm % 199character. 200The arguments must correspond properly (after type promotion) 201with the conversion specifier. 202After the 203.Cm % , 204the following appear in sequence: 205.Bl -bullet 206.It 207An optional field, consisting of a decimal digit string followed by a 208.Cm $ , 209specifying the next argument to access. 210If this field is not provided, the argument following the last 211argument accessed will be used. 212Arguments are numbered starting at 213.Cm 1 . 214If unaccessed arguments in the format string are interspersed with ones that 215are accessed the results will be indeterminate. 216.It 217Zero or more of the following flags: 218.Bl -tag -width ".So \ Sc (space)" 219.It Sq Cm # 220The value should be converted to an 221.Dq alternate form . 222For 223.Cm c , d , i , n , p , s , 224and 225.Cm u 226conversions, this option has no effect. 227For 228.Cm o 229conversions, the precision of the number is increased to force the first 230character of the output string to a zero. 231For 232.Cm x 233and 234.Cm X 235conversions, a non-zero result has the string 236.Ql 0x 237(or 238.Ql 0X 239for 240.Cm X 241conversions) prepended to it. 242For 243.Cm a , A , e , E , f , F , g , 244and 245.Cm G 246conversions, the result will always contain a decimal point, even if no 247digits follow it (normally, a decimal point appears in the results of 248those conversions only if a digit follows). 249For 250.Cm g 251and 252.Cm G 253conversions, trailing zeros are not removed from the result as they 254would otherwise be. 255.It So Cm 0 Sc (zero) 256Zero padding. 257For all conversions except 258.Cm n , 259the converted value is padded on the left with zeros rather than blanks. 260If a precision is given with a numeric conversion 261.Cm ( d , i , o , u , i , x , 262and 263.Cm X ) , 264the 265.Cm 0 266flag is ignored. 267.It Sq Cm \- 268A negative field width flag; 269the converted value is to be left adjusted on the field boundary. 270Except for 271.Cm n 272conversions, the converted value is padded on the right with blanks, 273rather than on the left with blanks or zeros. 274A 275.Cm \- 276overrides a 277.Cm 0 278if both are given. 279.It So "\ " Sc (space) 280A blank should be left before a positive number 281produced by a signed conversion 282.Cm ( a , A , d , e , E , f , F , g , G , 283or 284.Cm i ) . 285.It Sq Cm + 286A sign must always be placed before a 287number produced by a signed conversion. 288A 289.Cm + 290overrides a space if both are used. 291.It Sq Cm ' 292Decimal conversions 293.Cm ( d , u , 294or 295.Cm i ) 296or the integral portion of a floating point conversion 297.Cm ( f 298or 299.Cm F ) 300should be grouped and separated by thousands using 301the non-monetary separator returned by 302.Xr localeconv 3 . 303.El 304.It 305An optional decimal digit string specifying a minimum field width. 306If the converted value has fewer characters than the field width, it will 307be padded with spaces on the left (or right, if the left-adjustment 308flag has been given) to fill out 309the field width. 310.It 311An optional precision, in the form of a period 312.Cm \&. 313followed by an 314optional digit string. 315If the digit string is omitted, the precision is taken as zero. 316This gives the minimum number of digits to appear for 317.Cm d , i , o , u , x , 318and 319.Cm X 320conversions, the number of digits to appear after the decimal-point for 321.Cm a , A , e , E , f , 322and 323.Cm F 324conversions, the maximum number of significant digits for 325.Cm g 326and 327.Cm G 328conversions, or the maximum number of characters to be printed from a 329string for 330.Cm s 331conversions. 332.It 333An optional length modifier, that specifies the size of the argument. 334The following length modifiers are valid for the 335.Cm d , i , n , o , u , x , 336or 337.Cm X 338conversion: 339.Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *" 340.It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n 341.It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *" 342.It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *" 343.It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *" 344.It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *" 345.It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *" 346.It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *" 347.It Cm z Ta (see note) Ta Vt size_t Ta (see note) 348.It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *" 349.El 350.Pp 351Note: 352the 353.Cm t 354modifier, when applied to a 355.Cm o , u , x , 356or 357.Cm X 358conversion, indicates that the argument is of an unsigned type 359equivalent in size to a 360.Vt ptrdiff_t . 361The 362.Cm z 363modifier, when applied to a 364.Cm d 365or 366.Cm i 367conversion, indicates that the argument is of a signed type equivalent in 368size to a 369.Vt size_t . 370Similarly, when applied to an 371.Cm n 372conversion, it indicates that the argument is a pointer to a signed type 373equivalent in size to a 374.Vt size_t . 375.Pp 376The following length modifier is valid for the 377.Cm a , A , e , E , f , F , g , 378or 379.Cm G 380conversion: 381.Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G" 382.It Sy Modifier Ta Cm a , A , e , E , f , F , g , G 383.It Cm l No (ell) Ta Vt double 384(ignored, same behavior as without it) 385.It Cm L Ta Vt "long double" 386.El 387.Pp 388The following length modifier is valid for the 389.Cm c 390or 391.Cm s 392conversion: 393.Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *" 394.It Sy Modifier Ta Cm c Ta Cm s 395.It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *" 396.El 397.It 398A character that specifies the type of conversion to be applied. 399.El 400.Pp 401A field width or precision, or both, may be indicated by 402an asterisk 403.Ql * 404or an asterisk followed by one or more decimal digits and a 405.Ql $ 406instead of a 407digit string. 408In this case, an 409.Vt int 410argument supplies the field width or precision. 411A negative field width is treated as a left adjustment flag followed by a 412positive field width; a negative precision is treated as though it were 413missing. 414If a single format directive mixes positional 415.Pq Li nn$ 416and non-positional arguments, the results are undefined. 417.Pp 418The conversion specifiers and their meanings are: 419.Bl -tag -width ".Cm diouxX" 420.It Cm diouxX 421The 422.Vt int 423(or appropriate variant) argument is converted to signed decimal 424.Cm ( d 425and 426.Cm i ) , 427unsigned octal 428.Pq Cm o , 429unsigned decimal 430.Pq Cm u , 431or unsigned hexadecimal 432.Cm ( x 433and 434.Cm X ) 435notation. 436The letters 437.Dq Li abcdef 438are used for 439.Cm x 440conversions; the letters 441.Dq Li ABCDEF 442are used for 443.Cm X 444conversions. 445The precision, if any, gives the minimum number of digits that must 446appear; if the converted value requires fewer digits, it is padded on 447the left with zeros. 448.It Cm DOU 449The 450.Vt "long int" 451argument is converted to signed decimal, unsigned octal, or unsigned 452decimal, as if the format had been 453.Cm ld , lo , 454or 455.Cm lu 456respectively. 457These conversion characters are deprecated, and will eventually disappear. 458.It Cm eE 459The 460.Vt double 461argument is rounded and converted in the style 462.Sm off 463.Oo \- Oc Ar d Li \&. Ar ddd Li e \\*[Pm] Ar dd 464.Sm on 465where there is one digit before the 466decimal-point character 467and the number of digits after it is equal to the precision; 468if the precision is missing, 469it is taken as 6; if the precision is 470zero, no decimal-point character appears. 471An 472.Cm E 473conversion uses the letter 474.Ql E 475(rather than 476.Ql e ) 477to introduce the exponent. 478The exponent always contains at least two digits; if the value is zero, 479the exponent is 00. 480.Pp 481For 482.Cm a , A , e , E , f , F , g , 483and 484.Cm G 485conversions, positive and negative infinity are represented as 486.Li inf 487and 488.Li -inf 489respectively when using the lowercase conversion character, and 490.Li INF 491and 492.Li -INF 493respectively when using the uppercase conversion character. 494Similarly, NaN is represented as 495.Li nan 496when using the lowercase conversion, and 497.Li NAN 498when using the uppercase conversion. 499.It Cm fF 500The 501.Vt double 502argument is rounded and converted to decimal notation in the style 503.Sm off 504.Oo \- Oc Ar ddd Li \&. Ar ddd , 505.Sm on 506where the number of digits after the decimal-point character 507is equal to the precision specification. 508If the precision is missing, it is taken as 6; if the precision is 509explicitly zero, no decimal-point character appears. 510If a decimal point appears, at least one digit appears before it. 511.It Cm gG 512The 513.Vt double 514argument is converted in style 515.Cm f 516or 517.Cm e 518(or 519.Cm F 520or 521.Cm E 522for 523.Cm G 524conversions). 525The precision specifies the number of significant digits. 526If the precision is missing, 6 digits are given; if the precision is zero, 527it is treated as 1. 528Style 529.Cm e 530is used if the exponent from its conversion is less than \-4 or greater than 531or equal to the precision. 532Trailing zeros are removed from the fractional part of the result; a 533decimal point appears only if it is followed by at least one digit. 534.It Cm aA 535The 536.Vt double 537argument is rounded and converted to hexadecimal notation in the style 538.Sm off 539.Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \\*[Pm] Oc Ar d , 540.Sm on 541where the number of digits after the hexadecimal-point character 542is equal to the precision specification. 543If the precision is missing, it is taken as enough to represent 544the floating-point number exactly, and no rounding occurs. 545If the precision is zero, no hexadecimal-point character appears. 546The 547.Cm p 548is a literal character 549.Ql p , 550and the exponent consists of a positive or negative sign 551followed by a decimal number representing an exponent of 2. 552The 553.Cm A 554conversion uses the prefix 555.Dq Li 0X 556(rather than 557.Dq Li 0x ) , 558the letters 559.Dq Li ABCDEF 560(rather than 561.Dq Li abcdef ) 562to represent the hex digits, and the letter 563.Ql P 564(rather than 565.Ql p ) 566to separate the mantissa and exponent. 567.Pp 568Note that there may be multiple valid ways to represent floating-point 569numbers in this hexadecimal format. 570For example, 571.Li 0x1.92p+1 , 0x3.24p+0 , 0x6.48p-1 , 572and 573.Li 0xc.9p-2 574are all equivalent. 575.Fx 8.0 576and later always prints finite non-zero numbers using 577.Ql 1 578as the digit before the hexadecimal point. 579Zeroes are always represented with a mantissa of 0 (preceded by a 580.Ql - 581if appropriate) and an exponent of 582.Li +0 . 583.It Cm C 584Treated as 585.Cm c 586with the 587.Cm l 588(ell) modifier. 589.It Cm c 590The 591.Vt int 592argument is converted to an 593.Vt "unsigned char" , 594and the resulting character is written. 595.Pp 596If the 597.Cm l 598(ell) modifier is used, the 599.Vt wint_t 600argument shall be converted to a 601.Vt wchar_t , 602and the (potentially multi-byte) sequence representing the 603single wide character is written, including any shift sequences. 604If a shift sequence is used, the shift state is also restored 605to the original state after the character. 606.It Cm S 607Treated as 608.Cm s 609with the 610.Cm l 611(ell) modifier. 612.It Cm s 613The 614.Vt "char *" 615argument is expected to be a pointer to an array of character type (pointer 616to a string). 617Characters from the array are written up to (but not including) 618a terminating 619.Dv NUL 620character; 621if a precision is specified, no more than the number specified are 622written. 623If a precision is given, no null character 624need be present; if the precision is not specified, or is greater than 625the size of the array, the array must contain a terminating 626.Dv NUL 627character. 628.Pp 629If the 630.Cm l 631(ell) modifier is used, the 632.Vt "wchar_t *" 633argument is expected to be a pointer to an array of wide characters 634(pointer to a wide string). 635For each wide character in the string, the (potentially multi-byte) 636sequence representing the 637wide character is written, including any shift sequences. 638If any shift sequence is used, the shift state is also restored 639to the original state after the string. 640Wide characters from the array are written up to (but not including) 641a terminating wide 642.Dv NUL 643character; 644if a precision is specified, no more than the number of bytes specified are 645written (including shift sequences). 646Partial characters are never written. 647If a precision is given, no null character 648need be present; if the precision is not specified, or is greater than 649the number of bytes required to render the multibyte representation of 650the string, the array must contain a terminating wide 651.Dv NUL 652character. 653.It Cm p 654The 655.Vt "void *" 656pointer argument is printed in hexadecimal (as if by 657.Ql %#x 658or 659.Ql %#lx ) . 660.It Cm n 661The number of characters written so far is stored into the 662integer indicated by the 663.Vt "int *" 664(or variant) pointer argument. 665No argument is converted. 666.It Cm % 667A 668.Ql % 669is written. 670No argument is converted. 671The complete conversion specification 672is 673.Ql %% . 674.El 675.Pp 676The decimal point 677character is defined in the program's locale (category 678.Dv LC_NUMERIC ) . 679.Pp 680In no case does a non-existent or small field width cause truncation of 681a numeric field; if the result of a conversion is wider than the field 682width, the 683field is expanded to contain the conversion result. 684.Sh EXAMPLES 685To print a date and time in the form 686.Dq Li "Sunday, July 3, 10:02" , 687where 688.Fa weekday 689and 690.Fa month 691are pointers to strings: 692.Bd -literal -offset indent 693#include <stdio.h> 694fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", 695 weekday, month, day, hour, min); 696.Ed 697.Pp 698To print \*(Pi 699to five decimal places: 700.Bd -literal -offset indent 701#include <math.h> 702#include <stdio.h> 703fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0)); 704.Ed 705.Pp 706To allocate a 128 byte string and print into it: 707.Bd -literal -offset indent 708#include <stdio.h> 709#include <stdlib.h> 710#include <stdarg.h> 711char *newfmt(const char *fmt, ...) 712{ 713 char *p; 714 va_list ap; 715 if ((p = malloc(128)) == NULL) 716 return (NULL); 717 va_start(ap, fmt); 718 (void) vsnprintf(p, 128, fmt, ap); 719 va_end(ap); 720 return (p); 721} 722.Ed 723.Sh SECURITY CONSIDERATIONS 724The 725.Fn sprintf 726and 727.Fn vsprintf 728functions are easily misused in a manner which enables malicious users 729to arbitrarily change a running program's functionality through 730a buffer overflow attack. 731Because 732.Fn sprintf 733and 734.Fn vsprintf 735assume an infinitely long string, 736callers must be careful not to overflow the actual space; 737this is often hard to assure. 738For safety, programmers should use the 739.Fn snprintf 740interface instead. 741For example: 742.Bd -literal 743void 744foo(const char *arbitrary_string, const char *and_another) 745{ 746 char onstack[8]; 747 748#ifdef BAD 749 /* 750 * This first sprintf is bad behavior. Do not use sprintf! 751 */ 752 sprintf(onstack, "%s, %s", arbitrary_string, and_another); 753#else 754 /* 755 * The following two lines demonstrate better use of 756 * snprintf(). 757 */ 758 snprintf(onstack, sizeof(onstack), "%s, %s", arbitrary_string, 759 and_another); 760#endif 761} 762.Ed 763.Pp 764The 765.Fn printf 766and 767.Fn sprintf 768family of functions are also easily misused in a manner 769allowing malicious users to arbitrarily change a running program's 770functionality by either causing the program 771to print potentially sensitive data 772.Dq "left on the stack" , 773or causing it to generate a memory fault or bus error 774by dereferencing an invalid pointer. 775.Pp 776.Cm %n 777can be used to write arbitrary data to potentially carefully-selected 778addresses. 779Programmers are therefore strongly advised to never pass untrusted strings 780as the 781.Fa format 782argument, as an attacker can put format specifiers in the string 783to mangle your stack, 784leading to a possible security hole. 785This holds true even if the string was built using a function like 786.Fn snprintf , 787as the resulting string may still contain user-supplied conversion specifiers 788for later interpolation by 789.Fn printf . 790.Pp 791Always use the proper secure idiom: 792.Pp 793.Dl "snprintf(buffer, sizeof(buffer), \*q%s\*q, string);" 794.Sh COMPATIBILITY 795Many application writers used the name 796.Va dprintf 797before the 798.Fn dprintf 799function was introduced in 800.St -p1003.1 , 801so a prototype is not provided by default in order to avoid 802compatibility problems. 803Applications that wish to use the 804.Fn dprintf 805function described herein should either request a strict 806.St -p1003.1-2008 807environment by defining the macro 808.Dv _POSIX_C_SOURCE 809to the value 200809 or greater, or by defining the macro 810.Dv _WITH_DPRINTF , 811prior to the inclusion of 812.In stdio.h . 813For compatibility with GNU libc, defining either 814.Dv _BSD_SOURCE 815or 816.Dv _GNU_SOURCE 817prior to the inclusion of 818.In stdio.h 819will also make 820.Fn dprintf 821available. 822.Pp 823The conversion formats 824.Cm \&%D , \&%O , 825and 826.Cm %U 827are not standard and 828are provided only for backward compatibility. 829The effect of padding the 830.Cm %p 831format with zeros (either by the 832.Cm 0 833flag or by specifying a precision), and the benign effect (i.e., none) 834of the 835.Cm # 836flag on 837.Cm %n 838and 839.Cm %p 840conversions, as well as other 841nonsensical combinations such as 842.Cm %Ld , 843are not standard; such combinations 844should be avoided. 845.Sh ERRORS 846In addition to the errors documented for the 847.Xr write 2 848system call, the 849.Fn printf 850family of functions may fail if: 851.Bl -tag -width Er 852.It Bq Er EILSEQ 853An invalid wide character code was encountered. 854.It Bq Er ENOMEM 855Insufficient storage space is available. 856.El 857.Sh SEE ALSO 858.Xr printf 1 , 859.Xr fmtcheck 3 , 860.Xr scanf 3 , 861.Xr setlocale 3 , 862.Xr wprintf 3 863.Sh STANDARDS 864Subject to the caveats noted in the 865.Sx BUGS 866section below, the 867.Fn fprintf , 868.Fn printf , 869.Fn sprintf , 870.Fn vprintf , 871.Fn vfprintf , 872and 873.Fn vsprintf 874functions 875conform to 876.St -ansiC 877and 878.St -isoC-99 . 879With the same reservation, the 880.Fn snprintf 881and 882.Fn vsnprintf 883functions conform to 884.St -isoC-99 , 885while 886.Fn dprintf 887and 888.Fn vdprintf 889conform to 890.St -p1003.1-2008 . 891.Sh HISTORY 892The functions 893.Fn asprintf 894and 895.Fn vasprintf 896first appeared in the 897.Tn GNU C 898library. 899These were implemented by 900.An Peter Wemm Aq peter@FreeBSD.org 901in 902.Fx 2.2 , 903but were later replaced with a different implementation 904from 905.An Todd C. Miller Aq Todd.Miller@courtesan.com 906for 907.Ox 2.3 . 908The 909.Fn dprintf 910and 911.Fn vdprintf 912functions were added in 913.Fx 8.0 . 914.Sh BUGS 915The 916.Nm 917family of functions do not correctly handle multibyte characters in the 918.Fa format 919argument. 920