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) -1 is returned. ๐Ÿ’€
  • the length limit forces a stop. in this case, the number of bytes written to dest is 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 to dest โ€” excluding the terminating null byte ('\0') โ€” is returned. slay. โœจ
the programmer must ensure that there is room for at least dsize bytes at dest. 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