1wcstombs(3)                Library Functions Manual                wcstombs(3)
2
3
4

NAME

6       wcstombs - convert a wide-character string to a multibyte string
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdlib.h>
13
14       size_t wcstombs(char dest[restrict .n], const wchar_t *restrict src,
15                       size_t n);
16

DESCRIPTION

18       If  dest is not NULL, the wcstombs() function converts the wide-charac‐
19       ter string src to a multibyte string starting at dest.  At most n bytes
20       are  written to dest.  The sequence of characters placed in dest begins
21       in the initial shift state.  The conversion can stop for three reasons:
22
23       •  A wide character has been encountered that can not be represented as
24          a  multibyte  sequence  (according  to the current locale).  In this
25          case, (size_t) -1 is returned.
26
27       •  The length limit forces a stop.  In this case, the number  of  bytes
28          written  to  dest  is returned, but the shift state at this point is
29          lost.
30
31       •  The wide-character string has been completely  converted,  including
32          the terminating null wide character (L'\0').  In this case, the con‐
33          version ends in the initial shift state.  The number of bytes  writ‐
34          ten  to  dest,  excluding  the  terminating null byte ('\0'), is re‐
35          turned.
36
37       The programmer must ensure that there is room for at least n  bytes  at
38       dest.
39
40       If  dest  is  NULL, n is ignored, and the conversion proceeds as above,
41       except that the converted bytes are not written out to memory,  and  no
42       length limit exists.
43
44       In  order  to avoid the case 2 above, the programmer should make sure n
45       is greater than or equal to wcstombs(NULL,src,0)+1.
46

RETURN VALUE

48       The wcstombs() function returns the number of bytes that  make  up  the
49       converted  part  of a multibyte sequence, not including the terminating
50       null byte.  If a wide character was encountered which could not be con‐
51       verted, (size_t) -1 is returned.
52

ATTRIBUTES

54       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
55       tributes(7).
56
57       ┌────────────────────────────────────────────┬───────────────┬─────────┐
58Interface                                   Attribute     Value   
59       ├────────────────────────────────────────────┼───────────────┼─────────┤
60wcstombs()                                  │ Thread safety │ MT-Safe │
61       └────────────────────────────────────────────┴───────────────┴─────────┘
62

VERSIONS

64       The function wcsrtombs(3) provides a better interface to the same func‐
65       tionality.
66

STANDARDS

68       C11, POSIX.1-2008.
69

HISTORY

71       POSIX.1-2001, C99.
72

NOTES

74       The behavior of wcstombs() depends on the LC_CTYPE category of the cur‐
75       rent locale.
76

SEE ALSO

78       mblen(3), mbstowcs(3), mbtowc(3), wcsrtombs(3), wctomb(3)
79
80
81
82Linux man-pages 6.04              2023-03-30                       wcstombs(3)
Impressum