wcstombs(3)
๐ wcstombs(3) โ the wide-char-to-multibyte glow-up ๐
okay so bestie, welcome to the Library Functions Manual page for wcstombs(3). she lives in the Standard C library (libc, -lc) and her whole job is taking your wide-character string and turning it into a multibyte string. it's giving translator energy. ๐ฆ
โจ NAME โจ
wcstombs โ convert a wide-character string to a multibyte string ๐
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ SYNOPSIS ๐
#include <stdlib.h>
size_t wcstombs(size_t dsize;
char dest[restrict dsize], const wchar_t *restrict src,
size_t dsize);
๐ DESCRIPTION ๐
so here's the tea. if dest is not NULL, wcstombs() takes your wide-character string src and converts it into a multibyte string starting at dest. at most dsize bytes get written into dest. the sequence of characters placed in dest begins in the initial shift state. ๐ธ
the conversion can stop for three reasons, and honestly each one is a different vibe:
- a wide character showed up that can not be represented as a multibyte sequence (according to the current locale). in this case,
(size_t) -1is returned. ๐ - the length limit forces a stop. in this case, the number of bytes written to
destis returned, but the shift state at this point is lost. ๐ญ - the wide-character string has been completely converted, including the terminating null wide character (
L'\0'). in this case, the conversion ends in the initial shift state, and the number of bytes written todestโ excluding the terminating null byte ('\0') โ is returned. slay. โจ
the programmer must ensure that there is room for at leastdsizebytes atdest. no cap, that's on you. ๐ซถ
if dest is NULL, then dsize is ignored, and the conversion proceeds as described above โ except the converted bytes are not written out to memory, and no length limit exists. main character behavior, honestly. ๐
in order to avoid case 2 above, the programmer should make sure dsize is greater than or equal to wcstombs(NULL,src,0)+1. โ๏ธ
๐ฅ RETURN VALUE ๐ฅ
wcstombs() returns the number of bytes that make up the converted part of a multibyte sequence, not including the terminating null byte. ๐
but if a wide character was encountered which could not be converted, (size_t) -1 is returned. periodt. ๐ค
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, see attributes(7).
- Interface:
wcstombs() - Attribute: Thread safety
- Value: MT-Safe โ
(so yes bestie, she's thread safe. we love a stable queen.) ๐
โญ VERSIONS โญ
the function wcsrtombs(3) provides a better interface to the same functionality. just saying. ๐
๐ธ STANDARDS ๐ธ
C11, POSIX.1-2008.
๐ฆ HISTORY ๐ฆ
POSIX.1-2001, C99. she's been around. vintage. iconic. ๐
๐ NOTES ๐
the behavior of wcstombs() depends on the LC_CTYPE category of the current locale. so like, check your locale before you come for her. ๐
๐ SEE ALSO ๐
mblen(3), mbstowcs(3), mbtowc(3), wcsrtombs(3), wctomb(3)
and that's the whole page, bestie!! this one came from the Linux man-pages 6.20 collection, dated 2026-02-08. go forth and convert responsibly, mwah ๐ ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms