]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/wprintf.3
MB_CUR_MAX.3, MB_LEN_MAX.3, btowc.3, fgetwc.3, fgetws.3, fputwc.3, fputws.3, fwide...
[thirdparty/man-pages.git] / man3 / wprintf.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
fe382ebf 3.\" %%%LICENSE_START(GPLv2+_ONEPARA)
fea681da
MK
4.\" This is free documentation; you can redistribute it and/or
5.\" modify it under the terms of the GNU General Public License as
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
fe382ebf 8.\" %%%LICENSE_END
fea681da
MK
9.\"
10.\" References consulted:
11.\" GNU glibc-2 source code and manual
12.\" Dinkumware C library reference http://www.dinkumware.com/
008f1ecc 13.\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
fea681da
MK
14.\" ISO/IEC 9899:1999
15.\"
70225000 16.TH WPRINTF 3 2011-09-17 "GNU" "Linux Programmer's Manual"
fea681da 17.SH NAME
c13182ef 18wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf \- formatted
d0f17b57 19wide-character output conversion
fea681da
MK
20.SH SYNOPSIS
21.nf
22.B #include <stdio.h>
23.B #include <wchar.h>
24.sp
25.BI "int wprintf(const wchar_t *" format ", ...);"
26.BI "int fwprintf(FILE *" stream ", const wchar_t *" format ", ...);"
27.BI "int swprintf(wchar_t *" wcs ", size_t " maxlen ,
b9f02710 28.BI " const wchar_t *" format ", ...);"
fea681da 29.sp
fea681da
MK
30.BI "int vwprintf(const wchar_t *" format ", va_list " args );
31.BI "int vfwprintf(FILE *" stream ", const wchar_t *" format ", va_list " args );
32.BI "int vswprintf(wchar_t *" wcs ", size_t " maxlen ,
b9f02710 33.BI " const wchar_t *" format ", va_list " args );
fea681da 34.fi
cc4615cc
MK
35.sp
36.in -4n
37Feature Test Macro Requirements for glibc (see
38.BR feature_test_macros (7)):
39.in
40.sp
41.ad l
cfc2d88d 42All functions shown above:
c865a6eb 43.RS 4
cc4615cc
MK
44.\" .BR wprintf (),
45.\" .BR fwprintf (),
46.\" .BR swprintf (),
47.\" .BR vwprintf (),
48.\" .BR vfwprintf (),
49.\" .BR vswprintf ():
7d9e2c21 50_XOPEN_SOURCE\ >=\ 500 || _ISOC99_SOURCE ||
70225000
MK
51.br
52_ISOC95_SOURCE /* Since glibc 2.12 */ ||
53.br
7d9e2c21 54_POSIX_C_SOURCE\ >=\ 200112L;
c865a6eb
MK
55.br
56or
cc4615cc 57.I cc\ -std=c99
c865a6eb
MK
58.RE
59.ad
fea681da 60.SH DESCRIPTION
60a90ecd
MK
61The
62.BR wprintf ()
63family of functions is
c13182ef 64the wide-character equivalent of the
60a90ecd
MK
65.BR printf (3)
66family of functions.
c13182ef 67It performs formatted output of wide
fea681da
MK
68characters.
69.PP
60a90ecd
MK
70The
71.BR wprintf ()
72and
73.BR vwprintf ()
74functions
9bef72b5 75perform wide-character output to \fIstdout\fP.
9577265c 76\fIstdout\fP must not be byte oriented; see
60a90ecd
MK
77.BR fwide (3)
78for more information.
fea681da 79.PP
60a90ecd
MK
80The
81.BR fwprintf ()
82and
83.BR vfwprintf ()
84functions
d0f17b57 85perform wide-character output to \fIstream\fP.
9577265c 86\fIstream\fP must not be byte oriented; see
60a90ecd
MK
87.BR fwide (3)
88for more information.
fea681da 89.PP
60a90ecd
MK
90The
91.BR swprintf ()
92and
93.BR vswprintf ()
94functions
d0f17b57 95perform wide-character output
fea681da 96to an array of wide characters.
c13182ef
MK
97The programmer must ensure that there is
98room for at least \fImaxlen\fP wide
fea681da
MK
99characters at \fIwcs\fP.
100.PP
c13182ef 101These functions are like
60a90ecd
MK
102the
103.BR printf (3),
104.BR vprintf (3),
105.BR fprintf (3),
106.BR vfprintf (3),
107.BR sprintf (3),
108.BR vsprintf (3)
c13182ef 109functions except for the
fea681da
MK
110following differences:
111.TP
112.B \(bu
d0f17b57 113The \fIformat\fP string is a wide-character string.
fea681da
MK
114.TP
115.B \(bu
116The output consists of wide characters, not bytes.
117.TP
118.B \(bu
60a90ecd
MK
119.BR swprintf ()
120and
121.BR vswprintf ()
122take a \fImaxlen\fP argument,
123.BR sprintf (3)
124and
125.BR vsprintf (3)
126do not.
127.RB ( snprintf (3)
128and
129.BR vsnprintf (3)
fea681da
MK
130take a \fImaxlen\fP argument, but these functions do not return \-1 upon
131buffer overflow on Linux.)
132.PP
133The treatment of the conversion characters \fBc\fP and \fBs\fP is different:
134.TP
135.B c
136If no
137.B l
138modifier is present, the
139.I int
140argument is converted to a wide character by a call to the
fb186734 141.BR btowc (3)
fea681da
MK
142function, and the resulting wide character is written.
143If an
144.B l
145modifier is present, the
146.I wint_t
147(wide character) argument is written.
148.TP
149.B s
150If no
151.B l
152modifier is present: The
2b0fa182 153.I "const\ char\ *"
fea681da
MK
154argument is expected to be a pointer to an array of character type
155(pointer to a string) containing a multibyte character sequence beginning
c13182ef
MK
156in the initial shift state.
157Characters from the array are converted to
fea681da 158wide characters (each by a call to the
fb186734 159.BR mbrtowc (3)
fea681da 160function with a conversion state starting in the initial state before
c13182ef
MK
161the first byte).
162The resulting wide characters are written up to
163(but not including) the terminating null wide character.
164If a precision is
fea681da
MK
165specified, no more wide characters than the number specified are written.
166Note that the precision determines the number of
167.I wide characters
168written, not the number of
169.I bytes
170or
171.IR "screen positions" .
172The array must contain a terminating null byte, unless a precision is given
173and it is so small that the number of converted wide characters reaches it
c13182ef
MK
174before the end of the array is reached.
175If an
fea681da
MK
176.B l
177modifier is present: The
2b0fa182 178.I "const\ wchar_t\ *"
fea681da
MK
179argument is expected to be a pointer to an array of wide characters.
180Wide characters from the array are written up to (but not including) a
c13182ef
MK
181terminating null wide character.
182If a precision is specified, no more than
183the number specified are written.
184The array must contain a terminating null
fea681da
MK
185wide character, unless a precision is given and it is smaller than or equal
186to the number of wide characters in the array.
47297adb 187.SH RETURN VALUE
fea681da 188The functions return the number of wide characters written, excluding the
c13182ef 189terminating null wide character in
60a90ecd
MK
190case of the functions
191.BR swprintf ()
192and
193.BR vswprintf ().
c13182ef 194They return \-1 when an error occurs.
47297adb 195.SH CONFORMING TO
68e1685c 196C99.
fea681da 197.SH NOTES
d9bfdb9c 198The behavior of
60a90ecd
MK
199.BR wprintf ()
200et al. depends
1274071a
MK
201on the
202.B LC_CTYPE
203category of the
fea681da
MK
204current locale.
205.PP
206If the \fIformat\fP string contains non-ASCII wide characters, the program
1274071a
MK
207will only work correctly if the
208.B LC_CTYPE
209category of the current locale at
210run time is the same as the
211.B LC_CTYPE
212category of the current locale at
c13182ef
MK
213compile time.
214This is because the
9ff08aad 215.I wchar_t
a43eed0c 216representation is platform- and locale-dependent.
5260fe08 217(The glibc represents
fea681da 218wide characters using their Unicode (ISO-10646) code point, but other
c13182ef 219platforms don't do this.
68e1685c 220Also, the use of C99 universal character names
c13182ef
MK
221of the form \\unnnn does not solve this problem.)
222Therefore, in
fea681da
MK
223internationalized programs, the \fIformat\fP string should consist of ASCII
224wide characters only, or should be constructed at run time in an
75b94dc3 225internationalized way (e.g., using
fb186734 226.BR gettext (3)
fea681da 227or
fb186734 228.BR iconv (3),
fea681da 229followed by
fb186734 230.BR mbstowcs (3)).
47297adb 231.SH SEE ALSO
e37e3282
MK
232.BR fprintf (3),
233.BR fputwc (3),
234.BR fwide (3),
235.BR printf (3),
44bc0c36 236.BR snprintf (3)
988db661 237.\" .BR wscanf (3)