]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/wprintf.3
Libc-1272.200.26.tar.gz
[apple/libc.git] / stdio / FreeBSD / wprintf.3
CommitLineData
5b2abdfb
A
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.
5b2abdfb
A
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
9385eb3d 33.\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
974e3884 34.\" $FreeBSD$
5b2abdfb 35.\"
9385eb3d
A
36.Dd July 5, 2003
37.Dt WPRINTF 3
5b2abdfb
A
38.Os
39.Sh NAME
974e3884
A
40.Nm wprintf , fwprintf , swprintf ,
41.Nm vwprintf , vfwprintf , vswprintf
9385eb3d 42.Nd formatted wide character output conversion
5b2abdfb
A
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In stdio.h
9385eb3d 47.In wchar.h
5b2abdfb 48.Ft int
974e3884 49.Fn fwprintf "FILE * restrict stream" "const wchar_t * restrict format" ...
5b2abdfb 50.Ft int
974e3884 51.Fn swprintf "wchar_t * restrict ws" "size_t n" "const wchar_t * restrict format" ...
5b2abdfb 52.Ft int
974e3884 53.Fn wprintf "const wchar_t * restrict format" ...
5b2abdfb
A
54.In stdarg.h
55.Ft int
974e3884 56.Fn vfwprintf "FILE * restrict stream" "const wchar_t * restrict" "va_list ap"
5b2abdfb 57.Ft int
974e3884 58.Fn vswprintf "wchar_t * restrict ws" "size_t n" "const wchar_t *restrict format" "va_list ap"
5b2abdfb 59.Ft int
974e3884 60.Fn vwprintf "const wchar_t * restrict format" "va_list ap"
5b2abdfb
A
61.Sh DESCRIPTION
62The
9385eb3d 63.Fn wprintf
5b2abdfb 64family of functions produces output according to a
974e3884 65.Fa format
5b2abdfb 66as described below.
9385eb3d
A
67The
68.Fn wprintf
5b2abdfb 69and
9385eb3d
A
70.Fn vwprintf
71functions
5b2abdfb 72write output to
9385eb3d 73.Dv stdout ,
5b2abdfb 74the standard output stream;
9385eb3d 75.Fn fwprintf
5b2abdfb 76and
9385eb3d 77.Fn vfwprintf
5b2abdfb
A
78write output to the given output
79.Fa stream ;
9385eb3d 80.Fn swprintf
5b2abdfb 81and
9385eb3d
A
82.Fn vswprintf
83write to the wide character string
84.Fa ws .
5b2abdfb 85.Pp
ad3c9f2a
A
86Extended locale versions of these functions are documented in
87.Xr wprintf_l 3 .
88See
89.Xr xlocale 3
90for more information.
91.Pp
5b2abdfb
A
92These functions write the output under the control of a
93.Fa format
94string that specifies how subsequent arguments
95(or arguments accessed via the variable-length argument facilities of
96.Xr stdarg 3 )
97are converted for output.
98.Pp
99These functions return the number of characters printed
100(not including the trailing
ad3c9f2a 101.Ql \e0 ,
9385eb3d 102used to end output to strings).
5b2abdfb 103.Pp
9385eb3d
A
104The
105.Fn swprintf
5b2abdfb 106and
9385eb3d 107.Fn vswprintf
974e3884
A
108functions return the number of characters written (not including the terminating
109null wide character).
110These functions will fail (returning a negative value and setting
111.Va errno
112appropriately) if
9385eb3d 113.Fa n
974e3884
A
114or more wide characters were requested to be written.
115.Pp
116The other functions return the number of wide characters printed on success, or
117a negative value on faiure, setting
118.Va errno
119to indicate the error.
5b2abdfb
A
120.Pp
121The format string is composed of zero or more directives:
122ordinary
5b2abdfb
A
123characters (not
124.Cm % ) ,
125which are copied unchanged to the output stream;
126and conversion specifications, each of which results
127in fetching zero or more subsequent arguments.
128Each conversion specification is introduced by
129the
130.Cm %
131character.
132The arguments must correspond properly (after type promotion)
133with the conversion specifier.
134After the
135.Cm % ,
136the following appear in sequence:
137.Bl -bullet
138.It
139An optional field, consisting of a decimal digit string followed by a
140.Cm $ ,
141specifying the next argument to access.
142If this field is not provided, the argument following the last
143argument accessed will be used.
144Arguments are numbered starting at
145.Cm 1 .
146If unaccessed arguments in the format string are interspersed with ones that
147are accessed the results will be indeterminate.
148.It
149Zero or more of the following flags:
9385eb3d
A
150.Bl -tag -width ".So \ Sc (space)"
151.It Sq Cm #
152The value should be converted to an
5b2abdfb
A
153.Dq alternate form .
154For
155.Cm c , d , i , n , p , s ,
156and
157.Cm u
158conversions, this option has no effect.
159For
160.Cm o
161conversions, the precision of the number is increased to force the first
162character of the output string to a zero (except if a zero value is printed
163with an explicit precision of zero).
164For
165.Cm x
166and
167.Cm X
168conversions, a non-zero result has the string
169.Ql 0x
170(or
171.Ql 0X
172for
173.Cm X
174conversions) prepended to it.
175For
9385eb3d 176.Cm a , A , e , E , f , F , g ,
5b2abdfb
A
177and
178.Cm G
179conversions, the result will always contain a decimal point, even if no
180digits follow it (normally, a decimal point appears in the results of
181those conversions only if a digit follows).
182For
183.Cm g
184and
185.Cm G
186conversions, trailing zeros are not removed from the result as they
187would otherwise be.
9385eb3d
A
188.It So Cm 0 Sc (zero)
189Zero padding.
5b2abdfb
A
190For all conversions except
191.Cm n ,
192the converted value is padded on the left with zeros rather than blanks.
193If a precision is given with a numeric conversion
194.Cm ( d , i , o , u , i , x ,
195and
196.Cm X ) ,
197the
198.Cm 0
199flag is ignored.
9385eb3d
A
200.It Sq Cm \-
201A negative field width flag;
202the converted value is to be left adjusted on the field boundary.
5b2abdfb
A
203Except for
204.Cm n
205conversions, the converted value is padded on the right with blanks,
206rather than on the left with blanks or zeros.
207A
208.Cm \-
209overrides a
210.Cm 0
211if both are given.
9385eb3d
A
212.It So "\ " Sc (space)
213A blank should be left before a positive number
5b2abdfb 214produced by a signed conversion
9385eb3d 215.Cm ( a , A , d , e , E , f , F , g , G ,
5b2abdfb
A
216or
217.Cm i ) .
9385eb3d
A
218.It Sq Cm +
219A sign must always be placed before a
5b2abdfb
A
220number produced by a signed conversion.
221A
222.Cm +
223overrides a space if both are used.
9385eb3d
A
224.It Sq Cm '
225Decimal conversions
226.Cm ( d , u ,
227or
228.Cm i )
229or the integral portion of a floating point conversion
230.Cm ( f
231or
232.Cm F )
233should be grouped and separated by thousands using
234the non-monetary separator returned by
235.Xr localeconv 3 .
5b2abdfb
A
236.El
237.It
238An optional decimal digit string specifying a minimum field width.
239If the converted value has fewer characters than the field width, it will
240be padded with spaces on the left (or right, if the left-adjustment
241flag has been given) to fill out
242the field width.
243.It
244An optional precision, in the form of a period
245.Cm \&.
246followed by an
247optional digit string.
248If the digit string is omitted, the precision is taken as zero.
249This gives the minimum number of digits to appear for
250.Cm d , i , o , u , x ,
251and
252.Cm X
253conversions, the number of digits to appear after the decimal-point for
9385eb3d 254.Cm a , A , e , E , f ,
5b2abdfb 255and
9385eb3d 256.Cm F
5b2abdfb
A
257conversions, the maximum number of significant digits for
258.Cm g
259and
260.Cm G
261conversions, or the maximum number of characters to be printed from a
262string for
263.Cm s
264conversions.
265.It
9385eb3d
A
266An optional length modifier, that specifies the size of the argument.
267The following length modifiers are valid for the
268.Cm d , i , n , o , u , x ,
5b2abdfb
A
269or
270.Cm X
9385eb3d
A
271conversion:
272.Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *"
273.It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n
274.It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *"
275.It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *"
276.It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *"
277.It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *"
278.It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *"
279.It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *"
280.It Cm z Ta (see note) Ta Vt size_t Ta (see note)
281.It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *"
282.El
283.Pp
284Note:
285the
286.Cm t
287modifier, when applied to a
288.Cm o , u , x ,
5b2abdfb
A
289or
290.Cm X
9385eb3d
A
291conversion, indicates that the argument is of an unsigned type
292equivalent in size to a
293.Vt ptrdiff_t .
294The
295.Cm z
296modifier, when applied to a
297.Cm d
5b2abdfb 298or
9385eb3d
A
299.Cm i
300conversion, indicates that the argument is of a signed type equivalent in
301size to a
302.Vt size_t .
303Similarly, when applied to an
5b2abdfb 304.Cm n
9385eb3d
A
305conversion, it indicates that the argument is a pointer to a signed type
306equivalent in size to a
307.Vt size_t .
308.Pp
309The following length modifier is valid for the
310.Cm a , A , e , E , f , F , g ,
5b2abdfb
A
311or
312.Cm G
9385eb3d
A
313conversion:
314.Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
315.It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
316.It Cm L Ta Vt "long double"
317.El
318.Pp
319The following length modifier is valid for the
320.Cm c
321or
322.Cm s
323conversion:
324.Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *"
325.It Sy Modifier Ta Cm c Ta Cm s
326.It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
327.El
5b2abdfb
A
328.It
329A character that specifies the type of conversion to be applied.
330.El
331.Pp
332A field width or precision, or both, may be indicated by
333an asterisk
334.Ql *
335or an asterisk followed by one or more decimal digits and a
336.Ql $
337instead of a
338digit string.
339In this case, an
340.Vt int
341argument supplies the field width or precision.
342A negative field width is treated as a left adjustment flag followed by a
343positive field width; a negative precision is treated as though it were
344missing.
9385eb3d
A
345If a single format directive mixes positional
346.Pq Li nn$
5b2abdfb
A
347and non-positional arguments, the results are undefined.
348.Pp
349The conversion specifiers and their meanings are:
9385eb3d 350.Bl -tag -width ".Cm diouxX"
5b2abdfb
A
351.It Cm diouxX
352The
353.Vt int
354(or appropriate variant) argument is converted to signed decimal
355.Cm ( d
356and
357.Cm i ) ,
358unsigned octal
359.Pq Cm o ,
360unsigned decimal
361.Pq Cm u ,
362or unsigned hexadecimal
363.Cm ( x
364and
365.Cm X )
366notation.
367The letters
9385eb3d 368.Dq Li abcdef
5b2abdfb
A
369are used for
370.Cm x
371conversions; the letters
9385eb3d 372.Dq Li ABCDEF
5b2abdfb
A
373are used for
374.Cm X
375conversions.
376The precision, if any, gives the minimum number of digits that must
377appear; if the converted value requires fewer digits, it is padded on
378the left with zeros.
379.It Cm DOU
380The
9385eb3d 381.Vt "long int"
5b2abdfb
A
382argument is converted to signed decimal, unsigned octal, or unsigned
383decimal, as if the format had been
384.Cm ld , lo ,
385or
386.Cm lu
387respectively.
388These conversion characters are deprecated, and will eventually disappear.
389.It Cm eE
390The
391.Vt double
392argument is rounded and converted in the style
9385eb3d 393.Sm off
974e3884 394.Oo \- Oc Ar d Li \&. Ar ddd Li e \(+- Ar dd
9385eb3d 395.Sm on
5b2abdfb
A
396where there is one digit before the
397decimal-point character
398and the number of digits after it is equal to the precision;
399if the precision is missing,
400it is taken as 6; if the precision is
401zero, no decimal-point character appears.
402An
403.Cm E
404conversion uses the letter
9385eb3d 405.Ql E
5b2abdfb 406(rather than
9385eb3d 407.Ql e )
5b2abdfb
A
408to introduce the exponent.
409The exponent always contains at least two digits; if the value is zero,
410the exponent is 00.
9385eb3d
A
411.Pp
412For
413.Cm a , A , e , E , f , F , g ,
414and
415.Cm G
416conversions, positive and negative infinity are represented as
417.Li inf
418and
419.Li -inf
420respectively when using the lowercase conversion character, and
421.Li INF
422and
423.Li -INF
424respectively when using the uppercase conversion character.
425Similarly, NaN is represented as
426.Li nan
427when using the lowercase conversion, and
428.Li NAN
429when using the uppercase conversion.
430.It Cm fF
5b2abdfb
A
431The
432.Vt double
433argument is rounded and converted to decimal notation in the style
9385eb3d
A
434.Sm off
435.Oo \- Oc Ar ddd Li \&. Ar ddd ,
436.Sm on
5b2abdfb
A
437where the number of digits after the decimal-point character
438is equal to the precision specification.
439If the precision is missing, it is taken as 6; if the precision is
440explicitly zero, no decimal-point character appears.
441If a decimal point appears, at least one digit appears before it.
442.It Cm gG
443The
444.Vt double
445argument is converted in style
446.Cm f
447or
448.Cm e
449(or
9385eb3d
A
450.Cm F
451or
5b2abdfb
A
452.Cm E
453for
454.Cm G
455conversions).
456The precision specifies the number of significant digits.
457If the precision is missing, 6 digits are given; if the precision is zero,
458it is treated as 1.
459Style
460.Cm e
9385eb3d 461is used if the exponent from its conversion is less than \-4 or greater than
5b2abdfb
A
462or equal to the precision.
463Trailing zeros are removed from the fractional part of the result; a
464decimal point appears only if it is followed by at least one digit.
9385eb3d
A
465.It Cm aA
466The
467.Vt double
468argument is converted to hexadecimal notation in the style
469.Sm off
974e3884 470.Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \(+- Oc Ar d ,
9385eb3d
A
471.Sm on
472where the number of digits after the hexadecimal-point character
473is equal to the precision specification.
474If the precision is missing, it is taken as enough to exactly
475represent the floating-point number; if the precision is
476explicitly zero, no hexadecimal-point character appears.
477This is an exact conversion of the mantissa+exponent internal
478floating point representation; the
479.Sm off
480.Oo \- Oc Li 0x Ar h Li \&. Ar hhh
481.Sm on
482portion represents exactly the mantissa; only denormalized
483mantissas have a zero value to the left of the hexadecimal
484point.
485The
486.Cm p
487is a literal character
488.Ql p ;
489the exponent is preceded by a positive or negative sign
490and is represented in decimal, using only enough characters
491to represent the exponent.
492The
493.Cm A
494conversion uses the prefix
495.Dq Li 0X
496(rather than
497.Dq Li 0x ) ,
498the letters
499.Dq Li ABCDEF
500(rather than
501.Dq Li abcdef )
502to represent the hex digits, and the letter
503.Ql P
504(rather than
505.Ql p )
506to separate the mantissa and exponent.
507.It Cm C
508Treated as
509.Cm c
510with the
511.Cm l
512(ell) modifier.
5b2abdfb
A
513.It Cm c
514The
515.Vt int
516argument is converted to an
9385eb3d
A
517.Vt "unsigned char" ,
518then to a
519.Vt wchar_t
520as if by
521.Xr btowc 3 ,
5b2abdfb 522and the resulting character is written.
9385eb3d
A
523.Pp
524If the
525.Cm l
526(ell) modifier is used, the
527.Vt wint_t
528argument is converted to a
529.Vt wchar_t
530and written.
531.It Cm S
532Treated as
533.Cm s
534with the
535.Cm l
536(ell) modifier.
5b2abdfb
A
537.It Cm s
538The
9385eb3d 539.Vt "char *"
5b2abdfb 540argument is expected to be a pointer to an array of character type (pointer
9385eb3d
A
541to a string) containing a multibyte sequence.
542Characters from the array are converted to wide characters and written up to
543(but not including)
5b2abdfb
A
544a terminating
545.Dv NUL
546character;
547if a precision is specified, no more than the number specified are
548written.
549If a precision is given, no null character
550need be present; if the precision is not specified, or is greater than
551the size of the array, the array must contain a terminating
552.Dv NUL
553character.
9385eb3d
A
554.Pp
555If the
556.Cm l
557(ell) modifier is used, the
558.Vt "wchar_t *"
559argument is expected to be a pointer to an array of wide characters
560(pointer to a wide string).
561Each wide character in the string
562is written.
563Wide characters from the array are written up to (but not including)
564a terminating wide
565.Dv NUL
566character;
567if a precision is specified, no more than the number specified are
568written (including shift sequences).
569If a precision is given, no null character
570need be present; if the precision is not specified, or is greater than
571the number of characters in
572the string, the array must contain a terminating wide
573.Dv NUL
574character.
5b2abdfb
A
575.It Cm p
576The
9385eb3d 577.Vt "void *"
5b2abdfb
A
578pointer argument is printed in hexadecimal (as if by
579.Ql %#x
580or
581.Ql %#lx ) .
582.It Cm n
583The number of characters written so far is stored into the
584integer indicated by the
9385eb3d 585.Vt "int *"
5b2abdfb
A
586(or variant) pointer argument.
587No argument is converted.
588.It Cm %
589A
590.Ql %
591is written.
592No argument is converted.
593The complete conversion specification
594is
595.Ql %% .
596.El
597.Pp
9385eb3d
A
598The decimal point
599character is defined in the program's locale (category
600.Dv LC_NUMERIC ) .
601.Pp
5b2abdfb 602In no case does a non-existent or small field width cause truncation of
9385eb3d
A
603a numeric field; if the result of a conversion is wider than the field
604width, the
5b2abdfb 605field is expanded to contain the conversion result.
9385eb3d
A
606.Sh SECURITY CONSIDERATIONS
607Refer to
608.Xr printf 3 .
974e3884
A
609.Sh ERRORS
610Refer to
611.Xr printf 3 .
5b2abdfb 612.Sh SEE ALSO
9385eb3d
A
613.Xr btowc 3 ,
614.Xr fputws 3 ,
615.Xr printf 3 ,
616.Xr putwc 3 ,
617.Xr setlocale 3 ,
618.Xr wcsrtombs 3 ,
ad3c9f2a 619.Xr wprintf_l 3 ,
9385eb3d 620.Xr wscanf 3
5b2abdfb 621.Sh STANDARDS
9385eb3d
A
622Subject to the caveats noted in the
623.Sx BUGS
624section
625of
626.Xr printf 3 ,
627the
628.Fn wprintf ,
629.Fn fwprintf ,
630.Fn swprintf ,
631.Fn vwprintf ,
974e3884 632.Fn vfwprintf
5b2abdfb 633and
9385eb3d 634.Fn vswprintf
5b2abdfb
A
635functions
636conform to
9385eb3d 637.St -isoC-99 .