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

NAME

6       wcrtomb - convert a wide character to a multibyte sequence
7

SYNOPSIS

9       #include <wchar.h>
10
11       size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps);
12

DESCRIPTION

14       The  main  case for this function is when s is not NULL and wc is not a
15       null wide character (L'\0').  In this case, the wcrtomb() function con‐
16       verts  the wide character wc to its multibyte representation and stores
17       it at the beginning of the character array pointed to by s.  It updates
18       the shift state *ps, and returns the length of said multibyte represen‐
19       tation, that is, the number of bytes written at s.
20
21       A different case is when s is not NULL, but wc is a null wide character
22       (L'\0').   In this case, the wcrtomb() function stores at the character
23       array pointed to by s the shift sequence needed to bring  *ps  back  to
24       the initial state, followed by a '\0' byte.  It updates the shift state
25       *ps (i.e., brings it into the initial state), and returns the length of
26       the shift sequence plus one, that is, the number of bytes written at s.
27
28       A  third  case is when s is NULL.  In this case, wc is ignored, and the
29       function effectively returns
30
31           wcrtomb(buf, L'\0', ps)
32
33       where buf is an internal anonymous buffer.
34
35       In all of the above cases, if ps is  NULL,  a  static  anonymous  state
36       known only to the wcrtomb() function is used instead.
37

RETURN VALUE

39       The  wcrtomb()  function  returns the number of bytes that have been or
40       would have been written to the byte array at s.  If wc can not be  rep‐
41       resented  as  a  multibyte  sequence (according to the current locale),
42       (size_t) -1 is returned, and errno set to EILSEQ.
43

ATTRIBUTES

45       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
46       tributes(7).
47
48       ┌─────────────────────────┬───────────────┬────────────────────────────┐
49Interface                Attribute     Value                      
50       ├─────────────────────────┼───────────────┼────────────────────────────┤
51wcrtomb()                │ Thread safety │ MT-Unsafe race:wcrtomb/!ps │
52       └─────────────────────────┴───────────────┴────────────────────────────┘
53

CONFORMING TO

55       POSIX.1-2001, POSIX.1-2008, C99.
56

NOTES

58       The  behavior of wcrtomb() depends on the LC_CTYPE category of the cur‐
59       rent locale.
60
61       Passing NULL as ps is not multithread safe.
62

SEE ALSO

64       mbsinit(3), wcsrtombs(3)
65

COLOPHON

67       This page is part of release 5.12 of the Linux  man-pages  project.   A
68       description  of  the project, information about reporting bugs, and the
69       latest    version    of    this    page,    can     be     found     at
70       https://www.kernel.org/doc/man-pages/.
71
72
73
74GNU                               2021-03-22                        WCRTOMB(3)
Impressum