1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
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.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)printf.3 8.1 (Berkeley) 6/4/93
33 .\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
34 .\" $FreeBSD: src/lib/libc/stdio/wprintf.3,v 1.6 2007/01/09 00:28:08 imp Exp $
46 .Nd formatted wide character output conversion
54 .Fa "FILE *restrict stream"
55 .Fa "const wchar_t *restrict format"
60 .Fa "wchar_t *restrict ws"
62 .Fa "const wchar_t *restrict format"
67 .Fa "const wchar_t *restrict format"
75 .Fa "FILE *restrict stream"
76 .Fa "const wchar_t *restrict format"
81 .Fa "wchar_t *restrict ws"
83 .Fa "const wchar_t *restrict format"
88 .Fa "const wchar_t *restrict format"
94 family of functions produces output according to a
104 the standard output stream;
108 write output to the given output
113 write to the wide character string
116 Extended locale versions of these functions are documented in
120 for more information.
122 These functions write the output under the control of a
124 string that specifies how subsequent arguments
125 (or arguments accessed via the variable-length argument facilities of
127 are converted for output.
129 These functions return the number of characters printed
130 (not including the trailing
132 used to end output to strings).
138 functions will fail if
140 or more wide characters were requested to be written,
142 The format string is composed of zero or more directives:
146 which are copied unchanged to the output stream;
147 and conversion specifications, each of which results
148 in fetching zero or more subsequent arguments.
149 Each conversion specification is introduced by
153 The arguments must correspond properly (after type promotion)
154 with the conversion specifier.
157 the following appear in sequence:
160 An optional field, consisting of a decimal digit string followed by a
162 specifying the next argument to access.
163 If this field is not provided, the argument following the last
164 argument accessed will be used.
165 Arguments are numbered starting at
167 If unaccessed arguments in the format string are interspersed with ones that
168 are accessed the results will be indeterminate.
170 Zero or more of the following flags:
171 .Bl -tag -width ".So \ Sc (space)"
173 The value should be converted to an
176 .Cm c , d , i , n , p , s ,
179 conversions, this option has no effect.
182 conversions, the precision of the number is increased to force the first
183 character of the output string to a zero (except if a zero value is printed
184 with an explicit precision of zero).
189 conversions, a non-zero result has the string
195 conversions) prepended to it.
197 .Cm a , A , e , E , f , F , g ,
200 conversions, the result will always contain a decimal point, even if no
201 digits follow it (normally, a decimal point appears in the results of
202 those conversions only if a digit follows).
207 conversions, trailing zeros are not removed from the result as they
209 .It So Cm 0 Sc (zero)
211 For all conversions except
213 the converted value is padded on the left with zeros rather than blanks.
214 If a precision is given with a numeric conversion
215 .Cm ( d , i , o , u , i , x ,
222 A negative field width flag;
223 the converted value is to be left adjusted on the field boundary.
226 conversions, the converted value is padded on the right with blanks,
227 rather than on the left with blanks or zeros.
233 .It So "\ " Sc (space)
234 A blank should be left before a positive number
235 produced by a signed conversion
236 .Cm ( a , A , d , e , E , f , F , g , G ,
240 A sign must always be placed before a
241 number produced by a signed conversion.
244 overrides a space if both are used.
250 or the integral portion of a floating point conversion
254 should be grouped and separated by thousands using
255 the non-monetary separator returned by
259 An optional decimal digit string specifying a minimum field width.
260 If the converted value has fewer characters than the field width, it will
261 be padded with spaces on the left (or right, if the left-adjustment
262 flag has been given) to fill out
265 An optional precision, in the form of a period
268 optional digit string.
269 If the digit string is omitted, the precision is taken as zero.
270 This gives the minimum number of digits to appear for
271 .Cm d , i , o , u , x ,
274 conversions, the number of digits to appear after the decimal-point for
275 .Cm a , A , e , E , f ,
278 conversions, the maximum number of significant digits for
282 conversions, or the maximum number of characters to be printed from a
287 An optional length modifier, that specifies the size of the argument.
288 The following length modifiers are valid for the
289 .Cm d , i , n , o , u , x ,
293 .Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *"
294 .It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n
295 .It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *"
296 .It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *"
297 .It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *"
298 .It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *"
299 .It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *"
300 .It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *"
301 .It Cm z Ta (see note) Ta Vt size_t Ta (see note)
302 .It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *"
308 modifier, when applied to a
312 conversion, indicates that the argument is of an unsigned type
313 equivalent in size to a
317 modifier, when applied to a
321 conversion, indicates that the argument is of a signed type equivalent in
324 Similarly, when applied to an
326 conversion, it indicates that the argument is a pointer to a signed type
327 equivalent in size to a
330 The following length modifier is valid for the
331 .Cm a , A , e , E , f , F , g ,
335 .Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
336 .It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
337 .It Cm L Ta Vt "long double"
340 The following length modifier is valid for the
345 .Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *"
346 .It Sy Modifier Ta Cm c Ta Cm s
347 .It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
350 A character that specifies the type of conversion to be applied.
353 A field width or precision, or both, may be indicated by
356 or an asterisk followed by one or more decimal digits and a
362 argument supplies the field width or precision.
363 A negative field width is treated as a left adjustment flag followed by a
364 positive field width; a negative precision is treated as though it were
366 If a single format directive mixes positional
368 and non-positional arguments, the results are undefined.
370 The conversion specifiers and their meanings are:
371 .Bl -tag -width ".Cm diouxX"
375 (or appropriate variant) argument is converted to signed decimal
383 or unsigned hexadecimal
392 conversions; the letters
397 The precision, if any, gives the minimum number of digits that must
398 appear; if the converted value requires fewer digits, it is padded on
403 argument is converted to signed decimal, unsigned octal, or unsigned
404 decimal, as if the format had been
409 These conversion characters are deprecated, and will eventually disappear.
413 argument is rounded and converted in the style
415 .Oo \- Oc Ar d Li \&. Ar ddd Li e \\*[Pm] Ar dd
417 where there is one digit before the
418 decimal-point character
419 and the number of digits after it is equal to the precision;
420 if the precision is missing,
421 it is taken as 6; if the precision is
422 zero, no decimal-point character appears.
425 conversion uses the letter
429 to introduce the exponent.
430 The exponent always contains at least two digits; if the value is zero,
434 .Cm a , A , e , E , f , F , g ,
437 conversions, positive and negative infinity are represented as
441 respectively when using the lowercase conversion character, and
445 respectively when using the uppercase conversion character.
446 Similarly, NaN is represented as
448 when using the lowercase conversion, and
450 when using the uppercase conversion.
454 argument is rounded and converted to decimal notation in the style
456 .Oo \- Oc Ar ddd Li \&. Ar ddd ,
458 where the number of digits after the decimal-point character
459 is equal to the precision specification.
460 If the precision is missing, it is taken as 6; if the precision is
461 explicitly zero, no decimal-point character appears.
462 If a decimal point appears, at least one digit appears before it.
466 argument is converted in style
477 The precision specifies the number of significant digits.
478 If the precision is missing, 6 digits are given; if the precision is zero,
482 is used if the exponent from its conversion is less than \-4 or greater than
483 or equal to the precision.
484 Trailing zeros are removed from the fractional part of the result; a
485 decimal point appears only if it is followed by at least one digit.
489 argument is converted to hexadecimal notation in the style
491 .Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \\*[Pm] Oc Ar d ,
493 where the number of digits after the hexadecimal-point character
494 is equal to the precision specification.
495 If the precision is missing, it is taken as enough to exactly
496 represent the floating-point number; if the precision is
497 explicitly zero, no hexadecimal-point character appears.
498 This is an exact conversion of the mantissa+exponent internal
499 floating point representation; the
501 .Oo \- Oc Li 0x Ar h Li \&. Ar hhh
503 portion represents exactly the mantissa; only denormalized
504 mantissas have a zero value to the left of the hexadecimal
508 is a literal character
510 the exponent is preceded by a positive or negative sign
511 and is represented in decimal, using only enough characters
512 to represent the exponent.
515 conversion uses the prefix
523 to represent the hex digits, and the letter
527 to separate the mantissa and exponent.
537 argument is converted to an
538 .Vt "unsigned char" ,
543 and the resulting character is written.
547 (ell) modifier is used, the
549 argument is converted to a
561 argument is expected to be a pointer to an array of character type (pointer
562 to a string) containing a multibyte sequence.
563 Characters from the array are converted to wide characters and written up to
568 if a precision is specified, no more than the number specified are
570 If a precision is given, no null character
571 need be present; if the precision is not specified, or is greater than
572 the size of the array, the array must contain a terminating
578 (ell) modifier is used, the
580 argument is expected to be a pointer to an array of wide characters
581 (pointer to a wide string).
582 Each wide character in the string
584 Wide characters from the array are written up to (but not including)
588 if a precision is specified, no more than the number specified are
589 written (including shift sequences).
590 If a precision is given, no null character
591 need be present; if the precision is not specified, or is greater than
592 the number of characters in
593 the string, the array must contain a terminating wide
599 pointer argument is printed in hexadecimal (as if by
604 The number of characters written so far is stored into the
605 integer indicated by the
607 (or variant) pointer argument.
608 No argument is converted.
613 No argument is converted.
614 The complete conversion specification
620 character is defined in the program's locale (category
623 In no case does a non-existent or small field width cause truncation of
624 a numeric field; if the result of a conversion is wider than the field
626 field is expanded to contain the conversion result.
627 .Sh SECURITY CONSIDERATIONS
640 Subject to the caveats noted in the