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 .\" 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.
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
36 .\" @(#)printf.3 8.1 (Berkeley) 6/4/93
37 .\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
38 .\" $FreeBSD: src/lib/libc/stdio/wprintf.3,v 1.5 2003/07/05 07:55:34 tjr Exp $
44 .Nm wprintf , fwprintf , swprintf ,
45 .Nm vwprintf , vfwprintf , vswprintf
46 .Nd formatted wide character output conversion
53 .Fn fwprintf "FILE * restrict stream" "const wchar_t * restrict format" ...
55 .Fn swprintf "wchar_t * restrict ws" "size_t n" "const wchar_t * restrict format" ...
57 .Fn wprintf "const wchar_t * restrict format" ...
60 .Fn vfwprintf "FILE * restrict stream" "const wchar_t * restrict" "va_list ap"
62 .Fn vswprintf "wchar_t * restrict ws" "size_t n" "const wchar_t *restrict format" "va_list ap"
64 .Fn vwprintf "const wchar_t * restrict format" "va_list ap"
68 family of functions produces output according to a
78 the standard output stream;
82 write output to the given output
87 write to the wide character string
90 These functions write the output under the control of a
92 string that specifies how subsequent arguments
93 (or arguments accessed via the variable-length argument facilities of
95 are converted for output.
97 These functions return the number of characters printed
98 (not including the trailing
100 used to end output to strings).
106 functions will fail if
108 or more wide characters were requested to be written,
110 The format string is composed of zero or more directives:
114 which are copied unchanged to the output stream;
115 and conversion specifications, each of which results
116 in fetching zero or more subsequent arguments.
117 Each conversion specification is introduced by
121 The arguments must correspond properly (after type promotion)
122 with the conversion specifier.
125 the following appear in sequence:
128 An optional field, consisting of a decimal digit string followed by a
130 specifying the next argument to access.
131 If this field is not provided, the argument following the last
132 argument accessed will be used.
133 Arguments are numbered starting at
135 If unaccessed arguments in the format string are interspersed with ones that
136 are accessed the results will be indeterminate.
138 Zero or more of the following flags:
139 .Bl -tag -width ".So \ Sc (space)"
141 The value should be converted to an
144 .Cm c , d , i , n , p , s ,
147 conversions, this option has no effect.
150 conversions, the precision of the number is increased to force the first
151 character of the output string to a zero (except if a zero value is printed
152 with an explicit precision of zero).
157 conversions, a non-zero result has the string
163 conversions) prepended to it.
165 .Cm a , A , e , E , f , F , g ,
168 conversions, the result will always contain a decimal point, even if no
169 digits follow it (normally, a decimal point appears in the results of
170 those conversions only if a digit follows).
175 conversions, trailing zeros are not removed from the result as they
177 .It So Cm 0 Sc (zero)
179 For all conversions except
181 the converted value is padded on the left with zeros rather than blanks.
182 If a precision is given with a numeric conversion
183 .Cm ( d , i , o , u , i , x ,
190 A negative field width flag;
191 the converted value is to be left adjusted on the field boundary.
194 conversions, the converted value is padded on the right with blanks,
195 rather than on the left with blanks or zeros.
201 .It So "\ " Sc (space)
202 A blank should be left before a positive number
203 produced by a signed conversion
204 .Cm ( a , A , d , e , E , f , F , g , G ,
208 A sign must always be placed before a
209 number produced by a signed conversion.
212 overrides a space if both are used.
218 or the integral portion of a floating point conversion
222 should be grouped and separated by thousands using
223 the non-monetary separator returned by
227 An optional decimal digit string specifying a minimum field width.
228 If the converted value has fewer characters than the field width, it will
229 be padded with spaces on the left (or right, if the left-adjustment
230 flag has been given) to fill out
233 An optional precision, in the form of a period
236 optional digit string.
237 If the digit string is omitted, the precision is taken as zero.
238 This gives the minimum number of digits to appear for
239 .Cm d , i , o , u , x ,
242 conversions, the number of digits to appear after the decimal-point for
243 .Cm a , A , e , E , f ,
246 conversions, the maximum number of significant digits for
250 conversions, or the maximum number of characters to be printed from a
255 An optional length modifier, that specifies the size of the argument.
256 The following length modifiers are valid for the
257 .Cm d , i , n , o , u , x ,
261 .Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *"
262 .It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n
263 .It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *"
264 .It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *"
265 .It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *"
266 .It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *"
267 .It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *"
268 .It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *"
269 .It Cm z Ta (see note) Ta Vt size_t Ta (see note)
270 .It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *"
276 modifier, when applied to a
280 conversion, indicates that the argument is of an unsigned type
281 equivalent in size to a
285 modifier, when applied to a
289 conversion, indicates that the argument is of a signed type equivalent in
292 Similarly, when applied to an
294 conversion, it indicates that the argument is a pointer to a signed type
295 equivalent in size to a
298 The following length modifier is valid for the
299 .Cm a , A , e , E , f , F , g ,
303 .Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
304 .It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
305 .It Cm L Ta Vt "long double"
308 The following length modifier is valid for the
313 .Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *"
314 .It Sy Modifier Ta Cm c Ta Cm s
315 .It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
318 A character that specifies the type of conversion to be applied.
321 A field width or precision, or both, may be indicated by
324 or an asterisk followed by one or more decimal digits and a
330 argument supplies the field width or precision.
331 A negative field width is treated as a left adjustment flag followed by a
332 positive field width; a negative precision is treated as though it were
334 If a single format directive mixes positional
336 and non-positional arguments, the results are undefined.
338 The conversion specifiers and their meanings are:
339 .Bl -tag -width ".Cm diouxX"
343 (or appropriate variant) argument is converted to signed decimal
351 or unsigned hexadecimal
360 conversions; the letters
365 The precision, if any, gives the minimum number of digits that must
366 appear; if the converted value requires fewer digits, it is padded on
371 argument is converted to signed decimal, unsigned octal, or unsigned
372 decimal, as if the format had been
377 These conversion characters are deprecated, and will eventually disappear.
381 argument is rounded and converted in the style
383 .Oo \- Oc Ar d Li \&. Ar ddd Li e \\*[Pm] Ar dd
385 where there is one digit before the
386 decimal-point character
387 and the number of digits after it is equal to the precision;
388 if the precision is missing,
389 it is taken as 6; if the precision is
390 zero, no decimal-point character appears.
393 conversion uses the letter
397 to introduce the exponent.
398 The exponent always contains at least two digits; if the value is zero,
402 .Cm a , A , e , E , f , F , g ,
405 conversions, positive and negative infinity are represented as
409 respectively when using the lowercase conversion character, and
413 respectively when using the uppercase conversion character.
414 Similarly, NaN is represented as
416 when using the lowercase conversion, and
418 when using the uppercase conversion.
422 argument is rounded and converted to decimal notation in the style
424 .Oo \- Oc Ar ddd Li \&. Ar ddd ,
426 where the number of digits after the decimal-point character
427 is equal to the precision specification.
428 If the precision is missing, it is taken as 6; if the precision is
429 explicitly zero, no decimal-point character appears.
430 If a decimal point appears, at least one digit appears before it.
434 argument is converted in style
445 The precision specifies the number of significant digits.
446 If the precision is missing, 6 digits are given; if the precision is zero,
450 is used if the exponent from its conversion is less than \-4 or greater than
451 or equal to the precision.
452 Trailing zeros are removed from the fractional part of the result; a
453 decimal point appears only if it is followed by at least one digit.
457 argument is converted to hexadecimal notation in the style
459 .Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \\*[Pm] Oc Ar d ,
461 where the number of digits after the hexadecimal-point character
462 is equal to the precision specification.
463 If the precision is missing, it is taken as enough to exactly
464 represent the floating-point number; if the precision is
465 explicitly zero, no hexadecimal-point character appears.
466 This is an exact conversion of the mantissa+exponent internal
467 floating point representation; the
469 .Oo \- Oc Li 0x Ar h Li \&. Ar hhh
471 portion represents exactly the mantissa; only denormalized
472 mantissas have a zero value to the left of the hexadecimal
476 is a literal character
478 the exponent is preceded by a positive or negative sign
479 and is represented in decimal, using only enough characters
480 to represent the exponent.
483 conversion uses the prefix
491 to represent the hex digits, and the letter
495 to separate the mantissa and exponent.
505 argument is converted to an
506 .Vt "unsigned char" ,
511 and the resulting character is written.
515 (ell) modifier is used, the
517 argument is converted to a
529 argument is expected to be a pointer to an array of character type (pointer
530 to a string) containing a multibyte sequence.
531 Characters from the array are converted to wide characters and written up to
536 if a precision is specified, no more than the number specified are
538 If a precision is given, no null character
539 need be present; if the precision is not specified, or is greater than
540 the size of the array, the array must contain a terminating
546 (ell) modifier is used, the
548 argument is expected to be a pointer to an array of wide characters
549 (pointer to a wide string).
550 Each wide character in the string
552 Wide characters from the array are written up to (but not including)
556 if a precision is specified, no more than the number specified are
557 written (including shift sequences).
558 If a precision is given, no null character
559 need be present; if the precision is not specified, or is greater than
560 the number of characters in
561 the string, the array must contain a terminating wide
567 pointer argument is printed in hexadecimal (as if by
572 The number of characters written so far is stored into the
573 integer indicated by the
575 (or variant) pointer argument.
576 No argument is converted.
581 No argument is converted.
582 The complete conversion specification
588 character is defined in the program's locale (category
591 In no case does a non-existent or small field width cause truncation of
592 a numeric field; if the result of a conversion is wider than the field
594 field is expanded to contain the conversion result.
595 .Sh SECURITY CONSIDERATIONS
607 Subject to the caveats noted in the