1wprintf(3) Library Functions Manual wprintf(3)
2
3
4
6 wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf - formatted
7 wide-character output conversion
8
10 Standard C library (libc, -lc)
11
13 #include <stdio.h>
14 #include <wchar.h>
15
16 int wprintf(const wchar_t *restrict format, ...);
17 int fwprintf(FILE *restrict stream,
18 const wchar_t *restrict format, ...);
19 int swprintf(wchar_t wcs[restrict .maxlen], size_t maxlen,
20 const wchar_t *restrict format, ...);
21
22 int vwprintf(const wchar_t *restrict format, va_list args);
23 int vfwprintf(FILE *restrict stream,
24 const wchar_t *restrict format, va_list args);
25 int vswprintf(wchar_t wcs[restrict .maxlen], size_t maxlen,
26 const wchar_t *restrict format, va_list args);
27
28 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
29
30 All functions shown above:
31 _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
32 || _POSIX_C_SOURCE >= 200112L
33
35 The wprintf() family of functions is the wide-character equivalent of
36 the printf(3) family of functions. It performs formatted output of
37 wide characters.
38
39 The wprintf() and vwprintf() functions perform wide-character output to
40 stdout. stdout must not be byte oriented; see fwide(3) for more infor‐
41 mation.
42
43 The fwprintf() and vfwprintf() functions perform wide-character output
44 to stream. stream must not be byte oriented; see fwide(3) for more in‐
45 formation.
46
47 The swprintf() and vswprintf() functions perform wide-character output
48 to an array of wide characters. The programmer must ensure that there
49 is room for at least maxlen wide characters at wcs.
50
51 These functions are like the printf(3), vprintf(3), fprintf(3), vf‐
52 printf(3), sprintf(3), vsprintf(3) functions except for the following
53 differences:
54
55 • The format string is a wide-character string.
56
57 • The output consists of wide characters, not bytes.
58
59 • swprintf() and vswprintf() take a maxlen argument, sprintf(3)
60 and vsprintf(3) do not. (snprintf(3) and vsnprintf(3) take a
61 maxlen argument, but these functions do not return -1 upon buf‐
62 fer overflow on Linux.)
63
64 The treatment of the conversion characters c and s is different:
65
66 c If no l modifier is present, the int argument is converted to a
67 wide character by a call to the btowc(3) function, and the re‐
68 sulting wide character is written. If an l modifier is present,
69 the wint_t (wide character) argument is written.
70
71 s If no l modifier is present: the const char * argument is ex‐
72 pected to be a pointer to an array of character type (pointer to
73 a string) containing a multibyte character sequence beginning in
74 the initial shift state. Characters from the array are con‐
75 verted to wide characters (each by a call to the mbrtowc(3)
76 function with a conversion state starting in the initial state
77 before the first byte). The resulting wide characters are writ‐
78 ten up to (but not including) the terminating null wide charac‐
79 ter (L'\0'). If a precision is specified, no more wide charac‐
80 ters than the number specified are written. Note that the pre‐
81 cision determines the number of wide characters written, not the
82 number of bytes or screen positions. The array must contain a
83 terminating null byte ('\0'), unless a precision is given and it
84 is so small that the number of converted wide characters reaches
85 it before the end of the array is reached. If an l modifier is
86 present: the const wchar_t * argument is expected to be a
87 pointer to an array of wide characters. Wide characters from
88 the array are written up to (but not including) a terminating
89 null wide character. If a precision is specified, no more than
90 the number specified are written. The array must contain a ter‐
91 minating null wide character, unless a precision is given and it
92 is smaller than or equal to the number of wide characters in the
93 array.
94
96 The functions return the number of wide characters written, excluding
97 the terminating null wide character in case of the functions swprintf()
98 and vswprintf(). They return -1 when an error occurs.
99
101 For an explanation of the terms used in this section, see at‐
102 tributes(7).
103
104 ┌─────────────────────────────────────┬───────────────┬────────────────┐
105 │Interface │ Attribute │ Value │
106 ├─────────────────────────────────────┼───────────────┼────────────────┤
107 │wprintf(), fwprintf(), swprintf(), │ Thread safety │ MT-Safe locale │
108 │vwprintf(), vfwprintf(), vswprintf() │ │ │
109 └─────────────────────────────────────┴───────────────┴────────────────┘
110
112 C11, POSIX.1-2008.
113
115 POSIX.1-2001, C99.
116
118 The behavior of wprintf() et al. depends on the LC_CTYPE category of
119 the current locale.
120
121 If the format string contains non-ASCII wide characters, the program
122 will work correctly only if the LC_CTYPE category of the current locale
123 at run time is the same as the LC_CTYPE category of the current locale
124 at compile time. This is because the wchar_t representation is plat‐
125 form- and locale-dependent. (The glibc represents wide characters us‐
126 ing their Unicode (ISO/IEC 10646) code point, but other platforms don't
127 do this. Also, the use of C99 universal character names of the form
128 \unnnn does not solve this problem.) Therefore, in internationalized
129 programs, the format string should consist of ASCII wide characters on‐
130 ly, or should be constructed at run time in an internationalized way
131 (e.g., using gettext(3) or iconv(3), followed by mbstowcs(3)).
132
134 fprintf(3), fputwc(3), fwide(3), printf(3), snprintf(3)
135
136
137
138Linux man-pages 6.04 2023-03-30 wprintf(3)