xref: /netbsd-src/lib/libc/stdio/wprintf.3 (revision 14efb762fee6912444835a5a9a5bda0c9ac11171)
1*14efb762Sriastradh.\" $NetBSD: wprintf.3,v 1.9 2021/02/16 14:44:25 riastradh Exp $
2f432bbb6Schristos.\" Copyright (c) 1990, 1991, 1993
3f432bbb6Schristos.\"	The Regents of the University of California.  All rights reserved.
4f432bbb6Schristos.\"
5f432bbb6Schristos.\" This code is derived from software contributed to Berkeley by
6f432bbb6Schristos.\" Chris Torek and the American National Standards Committee X3,
7f432bbb6Schristos.\" on Information Processing Systems.
8f432bbb6Schristos.\"
9f432bbb6Schristos.\" Redistribution and use in source and binary forms, with or without
10f432bbb6Schristos.\" modification, are permitted provided that the following conditions
11f432bbb6Schristos.\" are met:
12f432bbb6Schristos.\" 1. Redistributions of source code must retain the above copyright
13f432bbb6Schristos.\"    notice, this list of conditions and the following disclaimer.
14f432bbb6Schristos.\" 2. Redistributions in binary form must reproduce the above copyright
15f432bbb6Schristos.\"    notice, this list of conditions and the following disclaimer in the
16f432bbb6Schristos.\"    documentation and/or other materials provided with the distribution.
17f432bbb6Schristos.\" 3. All advertising materials mentioning features or use of this software
18f432bbb6Schristos.\"    must display the following acknowledgement:
19f432bbb6Schristos.\"	This product includes software developed by the University of
20f432bbb6Schristos.\"	California, Berkeley and its contributors.
21f432bbb6Schristos.\" 4. Neither the name of the University nor the names of its contributors
22f432bbb6Schristos.\"    may be used to endorse or promote products derived from this software
23f432bbb6Schristos.\"    without specific prior written permission.
24f432bbb6Schristos.\"
25f432bbb6Schristos.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26f432bbb6Schristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27f432bbb6Schristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28f432bbb6Schristos.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29f432bbb6Schristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30f432bbb6Schristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31f432bbb6Schristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32f432bbb6Schristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33f432bbb6Schristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34f432bbb6Schristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35f432bbb6Schristos.\" SUCH DAMAGE.
36f432bbb6Schristos.\"
37f432bbb6Schristos.\"     @(#)printf.3	8.1 (Berkeley) 6/4/93
38f432bbb6Schristos.\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
39f432bbb6Schristos.\" $FreeBSD: src/lib/libc/stdio/wprintf.3,v 1.5 2003/07/05 07:55:34 tjr Exp $
40f432bbb6Schristos.\"
412f941c83Sjruoho.Dd April 30, 2010
42f432bbb6Schristos.Dt WPRINTF 3
43f432bbb6Schristos.Os
44f432bbb6Schristos.Sh NAME
45f432bbb6Schristos.Nm wprintf , fwprintf , swprintf ,
46f432bbb6Schristos.Nm vwprintf , vfwprintf , vswprintf
47f432bbb6Schristos.Nd formatted wide character output conversion
48f432bbb6Schristos.Sh LIBRARY
49f432bbb6Schristos.Lb libc
50f432bbb6Schristos.Sh SYNOPSIS
51f432bbb6Schristos.In stdio.h
52f432bbb6Schristos.In wchar.h
53f432bbb6Schristos.Ft int
54f432bbb6Schristos.Fn fwprintf "FILE * restrict stream" "const wchar_t * restrict format" ...
55f432bbb6Schristos.Ft int
56f432bbb6Schristos.Fn swprintf "wchar_t * restrict ws" "size_t n" "const wchar_t * restrict format" ...
57f432bbb6Schristos.Ft int
58f432bbb6Schristos.Fn wprintf "const wchar_t * restrict format" ...
59f432bbb6Schristos.In stdarg.h
60f432bbb6Schristos.Ft int
61f432bbb6Schristos.Fn vfwprintf "FILE * restrict stream" "const wchar_t * restrict" "va_list ap"
62f432bbb6Schristos.Ft int
63f432bbb6Schristos.Fn vswprintf "wchar_t * restrict ws" "size_t n" "const wchar_t *restrict format" "va_list ap"
64f432bbb6Schristos.Ft int
65f432bbb6Schristos.Fn vwprintf "const wchar_t * restrict format" "va_list ap"
66f432bbb6Schristos.Sh DESCRIPTION
67f432bbb6SchristosThe
68f432bbb6Schristos.Fn wprintf
69f432bbb6Schristosfamily of functions produces output according to a
70f432bbb6Schristos.Fa format
71f432bbb6Schristosas described below.
72f432bbb6SchristosThe
73f432bbb6Schristos.Fn wprintf
74f432bbb6Schristosand
75f432bbb6Schristos.Fn vwprintf
76f432bbb6Schristosfunctions
77f432bbb6Schristoswrite output to
78f432bbb6Schristos.Dv stdout ,
79f432bbb6Schristosthe standard output stream;
80f432bbb6Schristos.Fn fwprintf
81f432bbb6Schristosand
82f432bbb6Schristos.Fn vfwprintf
83f432bbb6Schristoswrite output to the given output
84f432bbb6Schristos.Fa stream ;
85f432bbb6Schristos.Fn swprintf
86f432bbb6Schristosand
87f432bbb6Schristos.Fn vswprintf
883d3c5d42Swizwrite to the wide-character string
89f432bbb6Schristos.Fa ws .
90f432bbb6Schristos.Pp
91f432bbb6SchristosThese functions write the output under the control of a
92f432bbb6Schristos.Fa format
93f432bbb6Schristosstring that specifies how subsequent arguments
94f432bbb6Schristos(or arguments accessed via the variable-length argument facilities of
95f432bbb6Schristos.Xr stdarg 3 )
96f432bbb6Schristosare converted for output.
97f432bbb6Schristos.Pp
98f432bbb6SchristosThe
99f432bbb6Schristos.Fn swprintf
100f432bbb6Schristosand
101f432bbb6Schristos.Fn vswprintf
102f432bbb6Schristosfunctions will fail if
103f432bbb6Schristos.Fa n
104f432bbb6Schristosor more wide characters were requested to be written,
105f432bbb6Schristos.Pp
106f432bbb6SchristosThe format string is composed of zero or more directives:
107f432bbb6Schristosordinary
108f432bbb6Schristoscharacters (not
109f432bbb6Schristos.Cm % ) ,
110f432bbb6Schristoswhich are copied unchanged to the output stream;
111f432bbb6Schristosand conversion specifications, each of which results
112f432bbb6Schristosin fetching zero or more subsequent arguments.
113f432bbb6SchristosEach conversion specification is introduced by
114f432bbb6Schristosthe
115f432bbb6Schristos.Cm %
116f432bbb6Schristoscharacter.
117f432bbb6SchristosThe arguments must correspond properly (after type promotion)
118f432bbb6Schristoswith the conversion specifier.
119f432bbb6SchristosAfter the
120f432bbb6Schristos.Cm % ,
121f432bbb6Schristosthe following appear in sequence:
122f432bbb6Schristos.Bl -bullet
123f432bbb6Schristos.It
124f432bbb6SchristosAn optional field, consisting of a decimal digit string followed by a
125f432bbb6Schristos.Cm $ ,
126f432bbb6Schristosspecifying the next argument to access.
127f432bbb6SchristosIf this field is not provided, the argument following the last
128f432bbb6Schristosargument accessed will be used.
129f432bbb6SchristosArguments are numbered starting at
130f432bbb6Schristos.Cm 1 .
131f432bbb6SchristosIf unaccessed arguments in the format string are interspersed with ones that
132f432bbb6Schristosare accessed the results will be indeterminate.
133f432bbb6Schristos.It
134f432bbb6SchristosZero or more of the following flags:
135f432bbb6Schristos.Bl -tag -width ".So \  Sc (space)"
136f432bbb6Schristos.It Sq Cm #
137f432bbb6SchristosThe value should be converted to an
138f432bbb6Schristos.Dq alternate form .
139f432bbb6SchristosFor
140f432bbb6Schristos.Cm c , d , i , n , p , s ,
141f432bbb6Schristosand
142f432bbb6Schristos.Cm u
143f432bbb6Schristosconversions, this option has no effect.
144f432bbb6SchristosFor
145f432bbb6Schristos.Cm o
146f432bbb6Schristosconversions, the precision of the number is increased to force the first
147f432bbb6Schristoscharacter of the output string to a zero (except if a zero value is printed
148f432bbb6Schristoswith an explicit precision of zero).
149f432bbb6SchristosFor
150f432bbb6Schristos.Cm x
151f432bbb6Schristosand
152f432bbb6Schristos.Cm X
153f432bbb6Schristosconversions, a non-zero result has the string
154f432bbb6Schristos.Ql 0x
155f432bbb6Schristos(or
156f432bbb6Schristos.Ql 0X
157f432bbb6Schristosfor
158f432bbb6Schristos.Cm X
159f432bbb6Schristosconversions) prepended to it.
160f432bbb6SchristosFor
161f432bbb6Schristos.Cm a , A , e , E , f , F , g ,
162f432bbb6Schristosand
163f432bbb6Schristos.Cm G
164f432bbb6Schristosconversions, the result will always contain a decimal point, even if no
165f432bbb6Schristosdigits follow it (normally, a decimal point appears in the results of
166f432bbb6Schristosthose conversions only if a digit follows).
167f432bbb6SchristosFor
168f432bbb6Schristos.Cm g
169f432bbb6Schristosand
170f432bbb6Schristos.Cm G
171f432bbb6Schristosconversions, trailing zeros are not removed from the result as they
172f432bbb6Schristoswould otherwise be.
173f432bbb6Schristos.It So Cm 0 Sc (zero)
174f432bbb6SchristosZero padding.
175f432bbb6SchristosFor all conversions except
176f432bbb6Schristos.Cm n ,
177f432bbb6Schristosthe converted value is padded on the left with zeros rather than blanks.
178f432bbb6SchristosIf a precision is given with a numeric conversion
179f432bbb6Schristos.Cm ( d , i , o , u , i , x ,
180f432bbb6Schristosand
181f432bbb6Schristos.Cm X ) ,
182f432bbb6Schristosthe
183f432bbb6Schristos.Cm 0
184f432bbb6Schristosflag is ignored.
185f432bbb6Schristos.It Sq Cm \-
186f432bbb6SchristosA negative field width flag;
187f432bbb6Schristosthe converted value is to be left adjusted on the field boundary.
188f432bbb6SchristosExcept for
189f432bbb6Schristos.Cm n
190f432bbb6Schristosconversions, the converted value is padded on the right with blanks,
191f432bbb6Schristosrather than on the left with blanks or zeros.
192f432bbb6SchristosA
193f432bbb6Schristos.Cm \-
194f432bbb6Schristosoverrides a
195f432bbb6Schristos.Cm 0
196f432bbb6Schristosif both are given.
197f432bbb6Schristos.It So "\ " Sc (space)
198f432bbb6SchristosA blank should be left before a positive number
199f432bbb6Schristosproduced by a signed conversion
200f432bbb6Schristos.Cm ( a , A , d , e , E , f , F , g , G ,
201f432bbb6Schristosor
202f432bbb6Schristos.Cm i ) .
203f432bbb6Schristos.It Sq Cm +
204f432bbb6SchristosA sign must always be placed before a
205f432bbb6Schristosnumber produced by a signed conversion.
206f432bbb6SchristosA
207f432bbb6Schristos.Cm +
208f432bbb6Schristosoverrides a space if both are used.
209f432bbb6Schristos.It Sq Cm '
210f432bbb6SchristosDecimal conversions
211f432bbb6Schristos.Cm ( d , u ,
212f432bbb6Schristosor
213f432bbb6Schristos.Cm i )
214f432bbb6Schristosor the integral portion of a floating point conversion
215f432bbb6Schristos.Cm ( f
216f432bbb6Schristosor
217f432bbb6Schristos.Cm F )
218f432bbb6Schristosshould be grouped and separated by thousands using
219f432bbb6Schristosthe non-monetary separator returned by
220f432bbb6Schristos.Xr localeconv 3 .
221f432bbb6Schristos.El
222f432bbb6Schristos.It
223f432bbb6SchristosAn optional decimal digit string specifying a minimum field width.
224f432bbb6SchristosIf the converted value has fewer characters than the field width, it will
225f432bbb6Schristosbe padded with spaces on the left (or right, if the left-adjustment
226f432bbb6Schristosflag has been given) to fill out
227f432bbb6Schristosthe field width.
228f432bbb6Schristos.It
229f432bbb6SchristosAn optional precision, in the form of a period
230f432bbb6Schristos.Cm \&.
231f432bbb6Schristosfollowed by an
232f432bbb6Schristosoptional digit string.
233f432bbb6SchristosIf the digit string is omitted, the precision is taken as zero.
234f432bbb6SchristosThis gives the minimum number of digits to appear for
235f432bbb6Schristos.Cm d , i , o , u , x ,
236f432bbb6Schristosand
237f432bbb6Schristos.Cm X
238f432bbb6Schristosconversions, the number of digits to appear after the decimal-point for
239f432bbb6Schristos.Cm a , A , e , E , f ,
240f432bbb6Schristosand
241f432bbb6Schristos.Cm F
242f432bbb6Schristosconversions, the maximum number of significant digits for
243f432bbb6Schristos.Cm g
244f432bbb6Schristosand
245f432bbb6Schristos.Cm G
246f432bbb6Schristosconversions, or the maximum number of characters to be printed from a
247f432bbb6Schristosstring for
248f432bbb6Schristos.Cm s
249f432bbb6Schristosconversions.
250f432bbb6Schristos.It
251f432bbb6SchristosAn optional length modifier, that specifies the size of the argument.
252f432bbb6SchristosThe following length modifiers are valid for the
253f432bbb6Schristos.Cm d , i , n , o , u , x ,
254f432bbb6Schristosor
255f432bbb6Schristos.Cm X
256f432bbb6Schristosconversion:
257f432bbb6Schristos.Bl -column ".Cm q Em (deprecated)" ".Vt signed char" ".Vt unsigned long long" ".Vt long long *"
258f432bbb6Schristos.It Sy Modifier Ta Cm d , i Ta Cm o , u , x , X Ta Cm n
259f432bbb6Schristos.It Cm hh Ta Vt "signed char" Ta Vt "unsigned char" Ta Vt "signed char *"
260f432bbb6Schristos.It Cm h Ta Vt short Ta Vt "unsigned short" Ta Vt "short *"
261f432bbb6Schristos.It Cm l No (ell) Ta Vt long Ta Vt "unsigned long" Ta Vt "long *"
262f432bbb6Schristos.It Cm ll No (ell ell) Ta Vt "long long" Ta Vt "unsigned long long" Ta Vt "long long *"
263f432bbb6Schristos.It Cm j Ta Vt intmax_t Ta Vt uintmax_t Ta Vt "intmax_t *"
264f432bbb6Schristos.It Cm t Ta Vt ptrdiff_t Ta (see note) Ta Vt "ptrdiff_t *"
265f432bbb6Schristos.It Cm z Ta (see note) Ta Vt size_t Ta (see note)
266f432bbb6Schristos.It Cm q Em (deprecated) Ta Vt quad_t Ta Vt u_quad_t Ta Vt "quad_t *"
267f432bbb6Schristos.El
268f432bbb6Schristos.Pp
269f432bbb6SchristosNote:
270f432bbb6Schristosthe
271f432bbb6Schristos.Cm t
272f432bbb6Schristosmodifier, when applied to a
273f432bbb6Schristos.Cm o , u , x ,
274f432bbb6Schristosor
275f432bbb6Schristos.Cm X
276f432bbb6Schristosconversion, indicates that the argument is of an unsigned type
277f432bbb6Schristosequivalent in size to a
278f432bbb6Schristos.Vt ptrdiff_t .
279f432bbb6SchristosThe
280f432bbb6Schristos.Cm z
281f432bbb6Schristosmodifier, when applied to a
282f432bbb6Schristos.Cm d
283f432bbb6Schristosor
284f432bbb6Schristos.Cm i
285f432bbb6Schristosconversion, indicates that the argument is of a signed type equivalent in
286f432bbb6Schristossize to a
287f432bbb6Schristos.Vt size_t .
288f432bbb6SchristosSimilarly, when applied to an
289f432bbb6Schristos.Cm n
290f432bbb6Schristosconversion, it indicates that the argument is a pointer to a signed type
291f432bbb6Schristosequivalent in size to a
292f432bbb6Schristos.Vt size_t .
293f432bbb6Schristos.Pp
294f432bbb6SchristosThe following length modifier is valid for the
295f432bbb6Schristos.Cm a , A , e , E , f , F , g ,
296f432bbb6Schristosor
297f432bbb6Schristos.Cm G
298f432bbb6Schristosconversion:
299f432bbb6Schristos.Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
300f432bbb6Schristos.It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
301f432bbb6Schristos.It Cm L Ta Vt "long double"
302f432bbb6Schristos.El
303f432bbb6Schristos.Pp
304f432bbb6SchristosThe following length modifier is valid for the
305f432bbb6Schristos.Cm c
306f432bbb6Schristosor
307f432bbb6Schristos.Cm s
308f432bbb6Schristosconversion:
309f432bbb6Schristos.Bl -column ".Sy Modifier" ".Vt wint_t" ".Vt wchar_t *"
310f432bbb6Schristos.It Sy Modifier Ta Cm c Ta Cm s
311f432bbb6Schristos.It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
312f432bbb6Schristos.El
313f432bbb6Schristos.It
314f432bbb6SchristosA character that specifies the type of conversion to be applied.
315f432bbb6Schristos.El
316f432bbb6Schristos.Pp
317f432bbb6SchristosA field width or precision, or both, may be indicated by
318f432bbb6Schristosan asterisk
319f432bbb6Schristos.Ql *
320f432bbb6Schristosor an asterisk followed by one or more decimal digits and a
321f432bbb6Schristos.Ql $
322f432bbb6Schristosinstead of a
323f432bbb6Schristosdigit string.
324f432bbb6SchristosIn this case, an
325f432bbb6Schristos.Vt int
326f432bbb6Schristosargument supplies the field width or precision.
327f432bbb6SchristosA negative field width is treated as a left adjustment flag followed by a
328f432bbb6Schristospositive field width; a negative precision is treated as though it were
329f432bbb6Schristosmissing.
330f432bbb6SchristosIf a single format directive mixes positional
331f432bbb6Schristos.Pq Li nn$
332f432bbb6Schristosand non-positional arguments, the results are undefined.
333f432bbb6Schristos.Pp
334f432bbb6SchristosThe conversion specifiers and their meanings are:
335f432bbb6Schristos.Bl -tag -width ".Cm diouxX"
336f432bbb6Schristos.It Cm diouxX
337f432bbb6SchristosThe
338f432bbb6Schristos.Vt int
339f432bbb6Schristos(or appropriate variant) argument is converted to signed decimal
340f432bbb6Schristos.Cm ( d
341f432bbb6Schristosand
342f432bbb6Schristos.Cm i ) ,
343f432bbb6Schristosunsigned octal
344f432bbb6Schristos.Pq Cm o ,
345f432bbb6Schristosunsigned decimal
346f432bbb6Schristos.Pq Cm u ,
347f432bbb6Schristosor unsigned hexadecimal
348f432bbb6Schristos.Cm ( x
349f432bbb6Schristosand
350f432bbb6Schristos.Cm X )
351f432bbb6Schristosnotation.
352f432bbb6SchristosThe letters
353f432bbb6Schristos.Dq Li abcdef
354f432bbb6Schristosare used for
355f432bbb6Schristos.Cm x
356f432bbb6Schristosconversions; the letters
357f432bbb6Schristos.Dq Li ABCDEF
358f432bbb6Schristosare used for
359f432bbb6Schristos.Cm X
360f432bbb6Schristosconversions.
361f432bbb6SchristosThe precision, if any, gives the minimum number of digits that must
362f432bbb6Schristosappear; if the converted value requires fewer digits, it is padded on
363f432bbb6Schristosthe left with zeros.
364f432bbb6Schristos.It Cm DOU
365f432bbb6SchristosThe
366f432bbb6Schristos.Vt "long int"
367f432bbb6Schristosargument is converted to signed decimal, unsigned octal, or unsigned
368f432bbb6Schristosdecimal, as if the format had been
369f432bbb6Schristos.Cm ld , lo ,
370f432bbb6Schristosor
371f432bbb6Schristos.Cm lu
372f432bbb6Schristosrespectively.
373f432bbb6SchristosThese conversion characters are deprecated, and will eventually disappear.
374f432bbb6Schristos.It Cm eE
375f432bbb6SchristosThe
376f432bbb6Schristos.Vt double
377f432bbb6Schristosargument is rounded and converted in the style
378f432bbb6Schristos.Sm off
37920fc76afSjoerg.Oo \- Oc Ar d Li \&. Ar ddd Li e \*[Pm] Ar dd
380f432bbb6Schristos.Sm on
381f432bbb6Schristoswhere there is one digit before the
382f432bbb6Schristosdecimal-point character
383f432bbb6Schristosand the number of digits after it is equal to the precision;
384f432bbb6Schristosif the precision is missing,
385f432bbb6Schristosit is taken as 6; if the precision is
386f432bbb6Schristoszero, no decimal-point character appears.
387f432bbb6SchristosAn
388f432bbb6Schristos.Cm E
389f432bbb6Schristosconversion uses the letter
390f432bbb6Schristos.Ql E
391f432bbb6Schristos(rather than
392f432bbb6Schristos.Ql e )
393f432bbb6Schristosto introduce the exponent.
394f432bbb6SchristosThe exponent always contains at least two digits; if the value is zero,
395f432bbb6Schristosthe exponent is 00.
396f432bbb6Schristos.Pp
397f432bbb6SchristosFor
398f432bbb6Schristos.Cm a , A , e , E , f , F , g ,
399f432bbb6Schristosand
400f432bbb6Schristos.Cm G
401f432bbb6Schristosconversions, positive and negative infinity are represented as
402f432bbb6Schristos.Li inf
403f432bbb6Schristosand
404f432bbb6Schristos.Li -inf
405f432bbb6Schristosrespectively when using the lowercase conversion character, and
406f432bbb6Schristos.Li INF
407f432bbb6Schristosand
408f432bbb6Schristos.Li -INF
409f432bbb6Schristosrespectively when using the uppercase conversion character.
410f432bbb6SchristosSimilarly, NaN is represented as
411f432bbb6Schristos.Li nan
412f432bbb6Schristoswhen using the lowercase conversion, and
413f432bbb6Schristos.Li NAN
414f432bbb6Schristoswhen using the uppercase conversion.
415f432bbb6Schristos.It Cm fF
416f432bbb6SchristosThe
417f432bbb6Schristos.Vt double
418f432bbb6Schristosargument is rounded and converted to decimal notation in the style
419f432bbb6Schristos.Sm off
420f432bbb6Schristos.Oo \- Oc Ar ddd Li \&. Ar ddd ,
421f432bbb6Schristos.Sm on
422f432bbb6Schristoswhere the number of digits after the decimal-point character
423f432bbb6Schristosis equal to the precision specification.
424f432bbb6SchristosIf the precision is missing, it is taken as 6; if the precision is
425f432bbb6Schristosexplicitly zero, no decimal-point character appears.
426f432bbb6SchristosIf a decimal point appears, at least one digit appears before it.
427f432bbb6Schristos.It Cm gG
428f432bbb6SchristosThe
429f432bbb6Schristos.Vt double
430f432bbb6Schristosargument is converted in style
431f432bbb6Schristos.Cm f
432f432bbb6Schristosor
433f432bbb6Schristos.Cm e
434f432bbb6Schristos(or
435f432bbb6Schristos.Cm F
436f432bbb6Schristosor
437f432bbb6Schristos.Cm E
438f432bbb6Schristosfor
439f432bbb6Schristos.Cm G
440f432bbb6Schristosconversions).
441f432bbb6SchristosThe precision specifies the number of significant digits.
442f432bbb6SchristosIf the precision is missing, 6 digits are given; if the precision is zero,
443f432bbb6Schristosit is treated as 1.
444f432bbb6SchristosStyle
445f432bbb6Schristos.Cm e
446f432bbb6Schristosis used if the exponent from its conversion is less than \-4 or greater than
447f432bbb6Schristosor equal to the precision.
448f432bbb6SchristosTrailing zeros are removed from the fractional part of the result; a
449f432bbb6Schristosdecimal point appears only if it is followed by at least one digit.
450f432bbb6Schristos.It Cm aA
451f432bbb6SchristosThe
452f432bbb6Schristos.Vt double
453f432bbb6Schristosargument is converted to hexadecimal notation in the style
454f432bbb6Schristos.Sm off
45520fc76afSjoerg.Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \*[Pm] Oc Ar d ,
456f432bbb6Schristos.Sm on
457f432bbb6Schristoswhere the number of digits after the hexadecimal-point character
458f432bbb6Schristosis equal to the precision specification.
459f432bbb6SchristosIf the precision is missing, it is taken as enough to exactly
460f432bbb6Schristosrepresent the floating-point number; if the precision is
461f432bbb6Schristosexplicitly zero, no hexadecimal-point character appears.
462*14efb762SriastradhThis is an exact conversion of the significand+exponent internal
463f432bbb6Schristosfloating point representation; the
464f432bbb6Schristos.Sm off
465f432bbb6Schristos.Oo \- Oc Li 0x Ar h Li \&. Ar hhh
466f432bbb6Schristos.Sm on
467*14efb762Sriastradhportion represents exactly the significand; only in subnormal numbers do
468*14efb762Sriastradhsignificands have a zero value to the left of the hexadecimal
469f432bbb6Schristospoint.
470f432bbb6SchristosThe
471f432bbb6Schristos.Cm p
472f432bbb6Schristosis a literal character
473f432bbb6Schristos.Ql p ;
474f432bbb6Schristosthe exponent is preceded by a positive or negative sign
475f432bbb6Schristosand is represented in decimal, using only enough characters
476f432bbb6Schristosto represent the exponent.
477f432bbb6SchristosThe
478f432bbb6Schristos.Cm A
479f432bbb6Schristosconversion uses the prefix
480f432bbb6Schristos.Dq Li 0X
481f432bbb6Schristos(rather than
482f432bbb6Schristos.Dq Li 0x ) ,
483f432bbb6Schristosthe letters
484f432bbb6Schristos.Dq Li ABCDEF
485f432bbb6Schristos(rather than
486f432bbb6Schristos.Dq Li abcdef )
487f432bbb6Schristosto represent the hex digits, and the letter
488f432bbb6Schristos.Ql P
489f432bbb6Schristos(rather than
490f432bbb6Schristos.Ql p )
491*14efb762Sriastradhto separate the significand and exponent.
492f432bbb6Schristos.It Cm C
493f432bbb6SchristosTreated as
494f432bbb6Schristos.Cm c
495f432bbb6Schristoswith the
496f432bbb6Schristos.Cm l
497f432bbb6Schristos(ell) modifier.
498f432bbb6Schristos.It Cm c
499f432bbb6SchristosThe
500f432bbb6Schristos.Vt int
501f432bbb6Schristosargument is converted to an
502f432bbb6Schristos.Vt "unsigned char" ,
503f432bbb6Schristosthen to a
504f432bbb6Schristos.Vt wchar_t
505f432bbb6Schristosas if by
506f432bbb6Schristos.Xr btowc 3 ,
507f432bbb6Schristosand the resulting character is written.
508f432bbb6Schristos.Pp
509f432bbb6SchristosIf the
510f432bbb6Schristos.Cm l
511f432bbb6Schristos(ell) modifier is used, the
512f432bbb6Schristos.Vt wint_t
513f432bbb6Schristosargument is converted to a
514f432bbb6Schristos.Vt wchar_t
515f432bbb6Schristosand written.
516f432bbb6Schristos.It Cm S
517f432bbb6SchristosTreated as
518f432bbb6Schristos.Cm s
519f432bbb6Schristoswith the
520f432bbb6Schristos.Cm l
521f432bbb6Schristos(ell) modifier.
522f432bbb6Schristos.It Cm s
523f432bbb6SchristosThe
524f432bbb6Schristos.Vt "char *"
525f432bbb6Schristosargument is expected to be a pointer to an array of character type (pointer
526f432bbb6Schristosto a string) containing a multibyte sequence.
527f432bbb6SchristosCharacters from the array are converted to wide characters and written up to
528f432bbb6Schristos(but not including)
529f432bbb6Schristosa terminating
530f432bbb6Schristos.Dv NUL
531f432bbb6Schristoscharacter;
532f432bbb6Schristosif a precision is specified, no more than the number specified are
533f432bbb6Schristoswritten.
534f432bbb6SchristosIf a precision is given, no null character
535f432bbb6Schristosneed be present; if the precision is not specified, or is greater than
536f432bbb6Schristosthe size of the array, the array must contain a terminating
537f432bbb6Schristos.Dv NUL
538f432bbb6Schristoscharacter.
539f432bbb6Schristos.Pp
540f432bbb6SchristosIf the
541f432bbb6Schristos.Cm l
542f432bbb6Schristos(ell) modifier is used, the
543f432bbb6Schristos.Vt "wchar_t *"
544f432bbb6Schristosargument is expected to be a pointer to an array of wide characters
545f432bbb6Schristos(pointer to a wide string).
546f432bbb6SchristosEach wide character in the string
547f432bbb6Schristosis written.
548f432bbb6SchristosWide characters from the array are written up to (but not including)
549f432bbb6Schristosa terminating wide
550f432bbb6Schristos.Dv NUL
551f432bbb6Schristoscharacter;
552f432bbb6Schristosif a precision is specified, no more than the number specified are
553f432bbb6Schristoswritten (including shift sequences).
554f432bbb6SchristosIf a precision is given, no null character
555f432bbb6Schristosneed be present; if the precision is not specified, or is greater than
556f432bbb6Schristosthe number of characters in
557f432bbb6Schristosthe string, the array must contain a terminating wide
558f432bbb6Schristos.Dv NUL
559f432bbb6Schristoscharacter.
560f432bbb6Schristos.It Cm p
561f432bbb6SchristosThe
562f432bbb6Schristos.Vt "void *"
563f432bbb6Schristospointer argument is printed in hexadecimal (as if by
564f432bbb6Schristos.Ql %#x
565f432bbb6Schristosor
566f432bbb6Schristos.Ql %#lx ) .
567f432bbb6Schristos.It Cm n
568f432bbb6SchristosThe number of characters written so far is stored into the
569f432bbb6Schristosinteger indicated by the
570f432bbb6Schristos.Vt "int *"
571f432bbb6Schristos(or variant) pointer argument.
572f432bbb6SchristosNo argument is converted.
573f432bbb6Schristos.It Cm %
574f432bbb6SchristosA
575f432bbb6Schristos.Ql %
576f432bbb6Schristosis written.
577f432bbb6SchristosNo argument is converted.
578f432bbb6SchristosThe complete conversion specification
579f432bbb6Schristosis
580f432bbb6Schristos.Ql %% .
581f432bbb6Schristos.El
582f432bbb6Schristos.Pp
583f432bbb6SchristosThe decimal point
584f432bbb6Schristoscharacter is defined in the program's locale (category
585f432bbb6Schristos.Dv LC_NUMERIC ) .
586f432bbb6Schristos.Pp
587f432bbb6SchristosIn no case does a non-existent or small field width cause truncation of
588f432bbb6Schristosa numeric field; if the result of a conversion is wider than the field
589f432bbb6Schristoswidth, the
590f432bbb6Schristosfield is expanded to contain the conversion result.
591ad61a2c7Syamt.Sh RETURN VALUES
592ad61a2c7SyamtThese functions return the number of characters printed
593ad61a2c7Syamt(not including the trailing
594ad61a2c7Syamt.Ql \e0
595ad61a2c7Syamtused to end output to strings).
596f432bbb6Schristos.Sh SEE ALSO
597f432bbb6Schristos.Xr btowc 3 ,
598f432bbb6Schristos.Xr fputws 3 ,
599f432bbb6Schristos.Xr printf 3 ,
600f432bbb6Schristos.Xr putwc 3 ,
601f432bbb6Schristos.Xr setlocale 3 ,
602f432bbb6Schristos.Xr wcsrtombs 3 ,
603f432bbb6Schristos.Xr wscanf 3
6042f941c83Sjruoho.Sh STANDARDS
6052f941c83SjruohoThe
606f432bbb6Schristos.Fn wprintf ,
607f432bbb6Schristos.Fn fwprintf ,
608f432bbb6Schristos.Fn swprintf ,
609f432bbb6Schristos.Fn vwprintf ,
610f432bbb6Schristos.Fn vfwprintf
611f432bbb6Schristosand
612f432bbb6Schristos.Fn vswprintf
613f432bbb6Schristosfunctions
614f432bbb6Schristosconform to
615f432bbb6Schristos.St -isoC-99 .
6161ad0e6c2Sjruoho.Sh SECURITY CONSIDERATIONS
6171ad0e6c2SjruohoSubject to the caveats noted in the
6181ad0e6c2Sjruoho.Xr printf 3 .
619