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
dsizebytes get written todest - the shift state
*psgets updated - the actual conversion is basically just calling
wcrtomb(dest, *src, ps)over and over again β as long as that call succeeds β and then bumpingdestforward by however many bytes got written, and bumping*srcforward 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,
*srcis left pointing at the invalid wide character,(size_t) -1gets returned, anderrnogets set toEILSEQ. - the size limit forces it to stop. in that case,
*srcis left pointing at the next wide character that still needs converting, and the number of bytes written todestgets 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*psback to its initial state π§. in this case,*srcgets set toNULL, and the number of bytes written todest(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 leastdsizebytes atdest. 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 theLC_CTYPEcategory of the current locale. so check your locale before you come for her. π - passing
NULLaspsis 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