1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
'\" t
.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
.\"
.\" SPDX-License-Identifier: GPL-2.0-or-later
.\"
.\" References consulted:
.\" GNU glibc-2 source code and manual
.\" Dinkumware C library reference http://www.dinkumware.com/
.\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
.\" ISO/IEC 9899:1999
.\"
.TH wprintf 3 2023-10-31 "Linux man-pages 6.06"
.SH NAME
wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf \- formatted
wide-character output conversion
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.B #include <stdio.h>
.B #include <wchar.h>
.P
.BI "int wprintf(const wchar_t *restrict " format ", ...);"
.BI "int fwprintf(FILE *restrict " stream ,
.BI " const wchar_t *restrict " format ", ...);"
.BI "int swprintf(wchar_t " wcs "[restrict ." maxlen "], size_t " maxlen ,
.BI " const wchar_t *restrict " format ", ...);"
.P
.BI "int vwprintf(const wchar_t *restrict " format ", va_list " args );
.BI "int vfwprintf(FILE *restrict " stream ,
.BI " const wchar_t *restrict " format ", va_list " args );
.BI "int vswprintf(wchar_t " wcs "[restrict ." maxlen "], size_t " maxlen ,
.BI " const wchar_t *restrict " format ", va_list " args );
.fi
.P
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
.P
All functions shown above:
.\" .BR wprintf (),
.\" .BR fwprintf (),
.\" .BR swprintf (),
.\" .BR vwprintf (),
.\" .BR vfwprintf (),
.\" .BR vswprintf ():
.nf
_XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
|| _POSIX_C_SOURCE >= 200112L
.fi
.SH DESCRIPTION
The
.BR wprintf ()
family of functions is
the wide-character equivalent of the
.BR printf (3)
family of functions.
It performs formatted output of wide
characters.
.P
The
.BR wprintf ()
and
.BR vwprintf ()
functions
perform wide-character output to
.IR stdout .
.I stdout
must not be byte oriented; see
.BR fwide (3)
for more information.
.P
The
.BR fwprintf ()
and
.BR vfwprintf ()
functions
perform wide-character output to
.IR stream .
.I stream
must not be byte oriented; see
.BR fwide (3)
for more information.
.P
The
.BR swprintf ()
and
.BR vswprintf ()
functions
perform wide-character output
to an array of wide characters.
The programmer must ensure that there is
room for at least
.I maxlen
wide
characters at
.IR wcs .
.P
These functions are like
the
.BR printf (3),
.BR vprintf (3),
.BR fprintf (3),
.BR vfprintf (3),
.BR sprintf (3),
.BR vsprintf (3)
functions except for the
following differences:
.TP
.B \[bu]
The
.I format
string is a wide-character string.
.TP
.B \[bu]
The output consists of wide characters, not bytes.
.TP
.B \[bu]
.BR swprintf ()
and
.BR vswprintf ()
take a
.I maxlen
argument,
.BR sprintf (3)
and
.BR vsprintf (3)
do not.
.RB ( snprintf (3)
and
.BR vsnprintf (3)
take a
.I maxlen
argument, but these functions do not return \-1 upon
buffer overflow on Linux.)
.P
The treatment of the conversion characters
.B c
and
.B s
is different:
.TP
.B c
If no
.B l
modifier is present, the
.I int
argument is converted to a wide character by a call to the
.BR btowc (3)
function, and the resulting wide character is written.
If an
.B l
modifier is present, the
.I wint_t
(wide character) argument is written.
.TP
.B s
If no
.B l
modifier is present: the
.I "const\ char\ *"
argument is expected to be a pointer to an array of character type
(pointer to a string) containing a multibyte character sequence beginning
in the initial shift state.
Characters from the array are converted to
wide characters (each by a call to the
.BR mbrtowc (3)
function with a conversion state starting in the initial state before
the first byte).
The resulting wide characters are written up to
(but not including) the terminating null wide character (L\[aq]\e0\[aq]).
If a precision is
specified, no more wide characters than the number specified are written.
Note that the precision determines the number of
.I wide characters
written, not the number of
.I bytes
or
.IR "screen positions" .
The array must contain a terminating null byte (\[aq]\e0\[aq]),
unless a precision is given
and it is so small that the number of converted wide characters reaches it
before the end of the array is reached.
If an
.B l
modifier is present: the
.I "const\ wchar_t\ *"
argument is expected to be a pointer to an array of wide characters.
Wide characters from the array are written up to (but not including) a
terminating null wide character.
If a precision is specified, no more than
the number specified are written.
The array must contain a terminating null
wide character, unless a precision is given and it is smaller than or equal
to the number of wide characters in the array.
.SH RETURN VALUE
The functions return the number of wide characters written, excluding the
terminating null wide character in
case of the functions
.BR swprintf ()
and
.BR vswprintf ().
They return \-1 when an error occurs.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.TS
allbox;
lbx lb lb
l l l.
Interface Attribute Value
T{
.na
.nh
.BR wprintf (),
.BR fwprintf (),
.BR swprintf (),
.BR vwprintf (),
.BR vfwprintf (),
.BR vswprintf ()
T} Thread safety MT-Safe locale
.TE
.SH STANDARDS
C11, POSIX.1-2008.
.SH HISTORY
POSIX.1-2001, C99.
.SH NOTES
The behavior of
.BR wprintf ()
et al. depends
on the
.B LC_CTYPE
category of the
current locale.
.P
If the
.I format
string contains non-ASCII wide characters, the program
will work correctly only if the
.B LC_CTYPE
category of the current locale at
run time is the same as the
.B LC_CTYPE
category of the current locale at
compile time.
This is because the
.I wchar_t
representation is platform- and locale-dependent.
(The glibc represents
wide characters using their Unicode (ISO/IEC 10646) code point, but other
platforms don't do this.
Also, the use of C99 universal character names
of the form \eunnnn does not solve this problem.)
Therefore, in
internationalized programs, the
.I format
string should consist of ASCII
wide characters only, or should be constructed at run time in an
internationalized way (e.g., using
.BR gettext (3)
or
.BR iconv (3),
followed by
.BR mbstowcs (3)).
.SH SEE ALSO
.BR fprintf (3),
.BR fputwc (3),
.BR fwide (3),
.BR printf (3),
.BR snprintf (3)
.\" .BR wscanf (3)
|