1WPRINTF(3)                 Linux Programmer's Manual                WPRINTF(3)
2
3
4

NAME

6       wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf - formatted
7       wide-character output conversion
8

SYNOPSIS

10       #include <stdio.h>
11       #include <wchar.h>
12
13       int wprintf(const wchar_t *restrict format, ...);
14       int fwprintf(FILE *restrict stream,
15                    const wchar_t *restrict format, ...);
16       int swprintf(wchar_t *restrict wcs, size_t maxlen,
17                    const wchar_t *restrict format, ...);
18
19       int vwprintf(const wchar_t *restrict format, va_list args);
20       int vfwprintf(FILE *restrict stream,
21                    const wchar_t *restrict format, va_list args);
22       int vswprintf(wchar_t *restrict wcs, size_t maxlen,
23                    const wchar_t *restrict format, va_list args);
24
25   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
26
27       All functions shown above:
28           _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
29               || _POSIX_C_SOURCE >= 200112L
30

DESCRIPTION

32       The wprintf() family of functions is the wide-character  equivalent  of
33       the  printf(3)  family  of  functions.  It performs formatted output of
34       wide characters.
35
36       The wprintf() and vwprintf() functions perform wide-character output to
37       stdout.  stdout must not be byte oriented; see fwide(3) for more infor‐
38       mation.
39
40       The fwprintf() and vfwprintf() functions perform wide-character  output
41       to stream.  stream must not be byte oriented; see fwide(3) for more in‐
42       formation.
43
44       The swprintf() and vswprintf() functions perform wide-character  output
45       to  an array of wide characters.  The programmer must ensure that there
46       is room for at least maxlen wide characters at wcs.
47
48       These functions are like the  printf(3),  vprintf(3),  fprintf(3),  vf‐
49       printf(3),  sprintf(3),  vsprintf(3) functions except for the following
50       differences:
51
52       The format string is a wide-character string.
53
54       The output consists of wide characters, not bytes.
55
56       •      swprintf() and vswprintf() take a  maxlen  argument,  sprintf(3)
57              and  vsprintf(3)  do  not.  (snprintf(3) and vsnprintf(3) take a
58              maxlen argument, but these functions do not return -1 upon  buf‐
59              fer overflow on Linux.)
60
61       The treatment of the conversion characters c and s is different:
62
63       c      If  no l modifier is present, the int argument is converted to a
64              wide character by a call to the btowc(3) function, and  the  re‐
65              sulting wide character is written.  If an l modifier is present,
66              the wint_t (wide character) argument is written.
67
68       s      If no l modifier is present: the const char *  argument  is  ex‐
69              pected to be a pointer to an array of character type (pointer to
70              a string) containing a multibyte character sequence beginning in
71              the  initial  shift  state.   Characters from the array are con‐
72              verted to wide characters (each by  a  call  to  the  mbrtowc(3)
73              function  with  a conversion state starting in the initial state
74              before the first byte).  The resulting wide characters are writ‐
75              ten  up to (but not including) the terminating null wide charac‐
76              ter (L'\0').  If a precision is specified, no more wide  charac‐
77              ters  than the number specified are written.  Note that the pre‐
78              cision determines the number of wide characters written, not the
79              number  of  bytes or screen positions.  The array must contain a
80              terminating null byte ('\0'), unless a precision is given and it
81              is so small that the number of converted wide characters reaches
82              it before the end of the array is reached.  If an l modifier  is
83              present:  the  const wchar_t *  argument  is  expected  to  be a
84              pointer to an array of wide characters.   Wide  characters  from
85              the  array  are  written up to (but not including) a terminating
86              null wide character.  If a precision is specified, no more  than
87              the number specified are written.  The array must contain a ter‐
88              minating null wide character, unless a precision is given and it
89              is smaller than or equal to the number of wide characters in the
90              array.
91

RETURN VALUE

93       The functions return the number of wide characters  written,  excluding
94       the terminating null wide character in case of the functions swprintf()
95       and vswprintf().  They return -1 when an error occurs.
96

ATTRIBUTES

98       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
99       tributes(7).
100
101       ┌─────────────────────────────────────┬───────────────┬────────────────┐
102Interface                            Attribute     Value          
103       ├─────────────────────────────────────┼───────────────┼────────────────┤
104wprintf(), fwprintf(), swprintf(),   │ Thread safety │ MT-Safe locale │
105vwprintf(), vfwprintf(), vswprintf() │               │                │
106       └─────────────────────────────────────┴───────────────┴────────────────┘
107

CONFORMING TO

109       POSIX.1-2001, POSIX.1-2008, C99.
110

NOTES

112       The behavior of wprintf() et al. depends on the  LC_CTYPE  category  of
113       the current locale.
114
115       If  the  format  string contains non-ASCII wide characters, the program
116       will work correctly only if the LC_CTYPE category of the current locale
117       at  run time is the same as the LC_CTYPE category of the current locale
118       at compile time.  This is because the wchar_t representation  is  plat‐
119       form-  and locale-dependent.  (The glibc represents wide characters us‐
120       ing their Unicode (ISO-10646) code point, but other platforms don't  do
121       this.   Also,  the  use  of  C99  universal character names of the form
122       \unnnn does not solve this problem.)  Therefore,  in  internationalized
123       programs, the format string should consist of ASCII wide characters on‐
124       ly, or should be constructed at run time in  an  internationalized  way
125       (e.g., using gettext(3) or iconv(3), followed by mbstowcs(3)).
126

SEE ALSO

128       fprintf(3), fputwc(3), fwide(3), printf(3), snprintf(3)
129

COLOPHON

131       This  page  is  part of release 5.13 of the Linux man-pages project.  A
132       description of the project, information about reporting bugs,  and  the
133       latest     version     of     this    page,    can    be    found    at
134       https://www.kernel.org/doc/man-pages/.
135
136
137
138GNU                               2021-03-22                        WPRINTF(3)
Impressum