1 .\" $NetBSD: wprintf.3,v 1.8 2010/12/16 17:42:27 wiz Exp $
2 .\" Copyright (c) 1990, 1991, 1993
3 .\" The Regents of the University of California. All rights reserved.
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Chris Torek and the American National Standards Committee X3,
7 .\" on Information Processing Systems.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed by the University of
20 .\" California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\" may be used to endorse or promote products derived from this software
23 .\" without specific prior written permission.
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 .\" @(#)printf.3 8.1 (Berkeley) 6/4/93
38 .\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
39 .\" $FreeBSD: src/lib/libc/stdio/wprintf.3,v 1.5 2003/07/05 07:55:34 tjr Exp $
45 .Nm wprintf , fwprintf , swprintf ,
46 .Nm vwprintf , vfwprintf , vswprintf
47 .Nd formatted wide character output conversion
54 .Fn fwprintf "FILE * restrict stream" "const wchar_t * restrict format" ...
56 .Fn swprintf "wchar_t * restrict ws" "size_t n" "const wchar_t * restrict format" ...
58 .Fn wprintf "const wchar_t * restrict format" ...
61 .Fn vfwprintf "FILE * restrict stream" "const wchar_t * restrict" "va_list ap"
63 .Fn vswprintf "wchar_t * restrict ws" "size_t n" "const wchar_t *restrict format" "va_list ap"
65 .Fn vwprintf "const wchar_t * restrict format" "va_list ap"
69 family of functions produces output according to a
79 the standard output stream;
83 write output to the given output
88 write to the wide-character string
91 These functions write the output under the control of a
93 string that specifies how subsequent arguments
94 (or arguments accessed via the variable-length argument facilities of
96 are converted for output.
102 functions will fail if
104 or more wide characters were requested to be written,
106 The format string is composed of zero or more directives:
110 which are copied unchanged to the output stream;
111 and conversion specifications, each of which results
112 in fetching zero or more subsequent arguments.
113 Each conversion specification is introduced by
117 The arguments must correspond properly (after type promotion)
118 with the conversion specifier.
121 the following appear in sequence:
124 An optional field, consisting of a decimal digit string followed by a
126 specifying the next argument to access.
127 If this field is not provided, the argument following the last
128 argument accessed will be used.
129 Arguments are numbered starting at
131 If unaccessed arguments in the format string are interspersed with ones that
132 are accessed the results will be indeterminate.
134 Zero or more of the following flags:
135 .Bl -tag -width ".So \ Sc (space)"
137 The value should be converted to an
140 .Cm c , d , i , n , p , s ,
143 conversions, this option has no effect.
146 conversions, the precision of the number is increased to force the first
147 character of the output string to a zero (except if a zero value is printed
148 with an explicit precision of zero).
153 conversions, a non-zero result has the string
159 conversions) prepended to it.
161 .Cm a , A , e , E , f , F , g ,
164 conversions, the result will always contain a decimal point, even if no
165 digits follow it (normally, a decimal point appears in the results of
166 those conversions only if a digit follows).
171 conversions, trailing zeros are not removed from the result as they
173 .It So Cm 0 Sc (zero)
175 For all conversions except
177 the converted value is padded on the left with zeros rather than blanks.
178 If a precision is given with a numeric conversion
179 .Cm ( d , i , o , u , i , x ,
186 A negative field width flag;
187 the converted value is to be left adjusted on the field boundary.
190 conversions, the converted value is padded on the right with blanks,
191 rather than on the left with blanks or zeros.
197 .It So "\ " Sc (space)
198 A blank should be left before a positive number
199 produced by a signed conversion
200 .Cm ( a , A , d , e , E , f , F , g , G ,
204 A sign must always be placed before a
205 number produced by a signed conversion.
208 overrides a space if both are used.
214 or the integral portion of a floating point conversion
218 should be grouped and separated by thousands using
219 the non-monetary separator returned by
223 An optional decimal digit string specifying a minimum field width.
224 If the converted value has fewer characters than the field width, it will
225 be padded with spaces on the left (or right, if the left-adjustment
226 flag has been given) to fill out
229 An optional precision, in the form of a period
232 optional digit string.
233 If the digit string is omitted, the precision is taken as zero.
234 This gives the minimum number of digits to appear for
235 .Cm d , i , o , u , x ,
238 conversions, the number of digits to appear after the decimal-point for
239 .Cm a , A , e , E , f ,
242 conversions, the maximum number of significant digits for
246 conversions, or the maximum number of characters to be printed from a
251 An optional length modifier, that specifies the size of the argument.
252 The following length modifiers are valid for the
253 .Cm d , i , n , o , u , x ,
257 .Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *"
258 .It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n
259 .It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *"
260 .It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *"
261 .It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *"
262 .It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *"
263 .It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *"
264 .It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *"
265 .It Cm z Ta (see note) Ta Vt size_t Ta (see note)
266 .It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *"
272 modifier, when applied to a
276 conversion, indicates that the argument is of an unsigned type
277 equivalent in size to a
281 modifier, when applied to a
285 conversion, indicates that the argument is of a signed type equivalent in
288 Similarly, when applied to an
290 conversion, it indicates that the argument is a pointer to a signed type
291 equivalent in size to a
294 The following length modifier is valid for the
295 .Cm a , A , e , E , f , F , g ,
299 .Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
300 .It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
301 .It Cm L Ta Vt "long double"
304 The following length modifier is valid for the
309 .Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *"
310 .It Sy Modifier Ta Cm c Ta Cm s
311 .It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
314 A character that specifies the type of conversion to be applied.
317 A field width or precision, or both, may be indicated by
320 or an asterisk followed by one or more decimal digits and a
326 argument supplies the field width or precision.
327 A negative field width is treated as a left adjustment flag followed by a
328 positive field width; a negative precision is treated as though it were
330 If a single format directive mixes positional
332 and non-positional arguments, the results are undefined.
334 The conversion specifiers and their meanings are:
335 .Bl -tag -width ".Cm diouxX"
339 (or appropriate variant) argument is converted to signed decimal
347 or unsigned hexadecimal
356 conversions; the letters
361 The precision, if any, gives the minimum number of digits that must
362 appear; if the converted value requires fewer digits, it is padded on
367 argument is converted to signed decimal, unsigned octal, or unsigned
368 decimal, as if the format had been
373 These conversion characters are deprecated, and will eventually disappear.
377 argument is rounded and converted in the style
379 .Oo \- Oc Ar d Li \&. Ar ddd Li e \*[Pm] Ar dd
381 where there is one digit before the
382 decimal-point character
383 and the number of digits after it is equal to the precision;
384 if the precision is missing,
385 it is taken as 6; if the precision is
386 zero, no decimal-point character appears.
389 conversion uses the letter
393 to introduce the exponent.
394 The exponent always contains at least two digits; if the value is zero,
398 .Cm a , A , e , E , f , F , g ,
401 conversions, positive and negative infinity are represented as
405 respectively when using the lowercase conversion character, and
409 respectively when using the uppercase conversion character.
410 Similarly, NaN is represented as
412 when using the lowercase conversion, and
414 when using the uppercase conversion.
418 argument is rounded and converted to decimal notation in the style
420 .Oo \- Oc Ar ddd Li \&. Ar ddd ,
422 where the number of digits after the decimal-point character
423 is equal to the precision specification.
424 If the precision is missing, it is taken as 6; if the precision is
425 explicitly zero, no decimal-point character appears.
426 If a decimal point appears, at least one digit appears before it.
430 argument is converted in style
441 The precision specifies the number of significant digits.
442 If the precision is missing, 6 digits are given; if the precision is zero,
446 is used if the exponent from its conversion is less than \-4 or greater than
447 or equal to the precision.
448 Trailing zeros are removed from the fractional part of the result; a
449 decimal point appears only if it is followed by at least one digit.
453 argument is converted to hexadecimal notation in the style
455 .Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \*[Pm] Oc Ar d ,
457 where the number of digits after the hexadecimal-point character
458 is equal to the precision specification.
459 If the precision is missing, it is taken as enough to exactly
460 represent the floating-point number; if the precision is
461 explicitly zero, no hexadecimal-point character appears.
462 This is an exact conversion of the mantissa+exponent internal
463 floating point representation; the
465 .Oo \- Oc Li 0x Ar h Li \&. Ar hhh
467 portion represents exactly the mantissa; only denormalized
468 mantissas have a zero value to the left of the hexadecimal
472 is a literal character
474 the exponent is preceded by a positive or negative sign
475 and is represented in decimal, using only enough characters
476 to represent the exponent.
479 conversion uses the prefix
487 to represent the hex digits, and the letter
491 to separate the mantissa and exponent.
501 argument is converted to an
502 .Vt "unsigned char" ,
507 and the resulting character is written.
511 (ell) modifier is used, the
513 argument is converted to a
525 argument is expected to be a pointer to an array of character type (pointer
526 to a string) containing a multibyte sequence.
527 Characters from the array are converted to wide characters and written up to
532 if a precision is specified, no more than the number specified are
534 If a precision is given, no null character
535 need be present; if the precision is not specified, or is greater than
536 the size of the array, the array must contain a terminating
542 (ell) modifier is used, the
544 argument is expected to be a pointer to an array of wide characters
545 (pointer to a wide string).
546 Each wide character in the string
548 Wide characters from the array are written up to (but not including)
552 if a precision is specified, no more than the number specified are
553 written (including shift sequences).
554 If a precision is given, no null character
555 need be present; if the precision is not specified, or is greater than
556 the number of characters in
557 the string, the array must contain a terminating wide
563 pointer argument is printed in hexadecimal (as if by
568 The number of characters written so far is stored into the
569 integer indicated by the
571 (or variant) pointer argument.
572 No argument is converted.
577 No argument is converted.
578 The complete conversion specification
584 character is defined in the program's locale (category
587 In no case does a non-existent or small field width cause truncation of
588 a numeric field; if the result of a conversion is wider than the field
590 field is expanded to contain the conversion result.
592 These functions return the number of characters printed
593 (not including the trailing
595 used to end output to strings).
616 .Sh SECURITY CONSIDERATIONS
617 Subject to the caveats noted in the