wcsrtombs(3)

πŸ’– wcsrtombs(3) πŸ’–

okay bestie, welcome to the Library Functions Manual page for wcsrtombs(3). she's a libc girlie and she's here to turn your wide characters into multibyte ones. let's go 🫢


✨ NAME ✨

wcsrtombs β€” convert a wide-character string to a multibyte string

πŸŽ€ LIBRARY πŸŽ€

Standard C library (libc, -lc)

🌸 SYNOPSIS 🌸

#include <wchar.h>

size_t wcsrtombs(size_t dsize;
                 char dest[restrict dsize],
                 const wchar_t **restrict src,
                 size_t dsize, mbstate_t *restrict ps);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie. if dest is not NULL, wcsrtombs() converts the wide-character string *src into a multibyte string, and it starts writing at dest. ✨

  • at most dsize bytes get written to dest
  • the shift state *ps gets updated
  • the actual conversion is basically just calling wcrtomb(dest, *src, ps) over and over again β€” as long as that call succeeds β€” and then bumping dest forward by however many bytes got written, and bumping *src forward by one. periodt.

and the conversion can stop for three reasons:

  • a wide character shows up that can NOT be represented as a multibyte sequence (per the current locale) 😭. in that case, *src is left pointing at the invalid wide character, (size_t) -1 gets returned, and errno gets set to EILSEQ.
  • the size limit forces it to stop. in that case, *src is left pointing at the next wide character that still needs converting, and the number of bytes written to dest gets returned. no more, no less.
  • the wide-character string got completely converted, including the terminating null wide character (L'\0') β€” which, side note, has the side effect of bringing *ps back to its initial state 🧚. in this case, *src gets set to NULL, and the number of bytes written to dest (not counting the terminating null byte '\0') is returned.

if dest is NULL, then dsize is ignored entirely, and the conversion proceeds just like above β€” EXCEPT the converted bytes never get written out to memory, and there's no size limit at all. lowkey freeing honestly.

in both of the above cases, if ps is NULL, a static anonymous state that only wcsrtombs() itself knows about gets used instead. iykyk.

⚠️ bestie, listen. the programmer has to make sure there's room for at least dsize bytes at dest. that's on you, not on her. πŸ’…

πŸ‘‘ RETURN VALUE πŸ‘‘

wcsrtombs() returns the number of bytes that make up the converted part of the multibyte sequence β€” not including the terminating null byte.

if a wide character showed up that couldn't be converted, (size_t) -1 is returned, and errno is set to EILSEQ. πŸ’€

πŸ”₯ ATTRIBUTES πŸ”₯

for an explanation of the terms used in this section, see attributes(7).

  • Interface: wcsrtombs()
  • Attribute: Thread safety
  • Value: MT-Unsafe race:wcsrtombs/!ps

so yeah, thread safety is giving "it depends". 🌈

⭐ STANDARDS ⭐

C11, POSIX.1-2008. iconic behavior, no cap.

πŸ’œ HISTORY πŸ’œ

POSIX.1-2001, C99. she's been around, she's a legend.

🌈 NOTES 🌈

  • the behavior of wcsrtombs() depends on the LC_CTYPE category of the current locale. so check your locale before you come for her. πŸŽ€
  • passing NULL as ps is not multithread safe. not me warning you twice, but like, i am warning you twice. πŸ™ˆ

🌟 SEE ALSO 🌟


and that's the whole page, bestie πŸ’– this was Linux man-pages 6.20, dated 2026-02-08 β€” go forth and convert those wide characters 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