mbsnrtowcs(3)
β¨ mbsnrtowcs β¨
okay bestie so this is mbsnrtowcs from the mbsnrtowcs(3) manual, and she is the multibyte-string-to-wide-character-string converter with a byte limit. she lives in the Standard C library, so you get her with libc, -lc. no cap π
π LIBRARY
Standard C library (libc, -lc). she's already in the building, you just gotta link her.
π¦ SYNOPSIS
#include <wchar.h>
size_t mbsnrtowcs(size_t size;
wchar_t dest[restrict size], const char **restrict src,
size_t nms, size_t size, mbstate_t *restrict ps);
Feature Test Macro Requirements for glibc (peep feature_test_macros(7) for the full tea):
mbsnrtowcs():- Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
- Before glibc 2.10:
_GNU_SOURCE
- Since glibc 2.10:
π DESCRIPTION
so mbsnrtowcs() is literally just like mbsrtowcs(3), except the number of bytes she converts, starting at *src, is capped at most nms bytes. that's the whole plot twist. π
If dest is not NULL, mbsnrtowcs() converts at most nms bytes from the multibyte string *src into a wide-character string starting at dest. At most size wide characters get written to dest. The shift state *ps gets updated. Under the hood the conversion is effectively done by repeatedly calling mbrtowc(dest, *src, n, ps) where n is some positive number, for as long as that call succeeds, and then bumping dest up by one and *src up by however many bytes got consumed. π
The conversion can stop for three reasons:
- An invalid multibyte sequence has been encountered. In this case,
*srcis left pointing at the invalid multibyte sequence,(size_t) -1is returned, anderrnois set toEILSEQ. π - The
nmslimit forces a stop, orsizenon-L'\0'wide characters have been stored atdest. In this case,*srcis left pointing at the next multibyte sequence to be converted, and the number of wide characters written todestis returned. slay, partial progress. - The multibyte string has been completely converted, including the terminating null wide character (
'\0') β which has the side effect of bringing*psback to the initial state. In this case,*srcis set toNULL, and the number of wide characters written todest, excluding the terminating null wide character, is returned. π
According to POSIX.1, if the input buffer ends with an incomplete character, it is unspecified whether conversion stops at the end of the previous character (if any), or at the end of the input buffer. The glibc implementation adopts the former behavior. iykyk β¨
If dest is NULL, size is ignored, and the conversion proceeds as described above, except that the converted wide characters are not written out to memory, and no destination size limit exists. (yes, she's just vibing and counting.)
In both of the above cases, if ps is NULL, a static anonymous state known only to the mbsnrtowcs() function is used instead.
β οΈ The programmer must ensure that there is room for at leastsizewide characters atdest. no room = no vibe. π«Ά
πΈ RETURN VALUE
mbsnrtowcs() returns the number of wide characters that make up the converted part of the wide-character string, not including the terminating null wide character. If an invalid multibyte sequence was encountered, (size_t) -1 is returned, and errno set to EILSEQ.
π ATTRIBUTES
for an explanation of the terms used in this section, go see attributes(7).
- Interface:
mbsnrtowcs() - Attribute: Thread safety
- Value:
MT-Unsafe race:mbsnrtowcs/!ps
π STANDARDS
POSIX.1-2008. she's official, bestie.
β NOTES
- The behavior of
mbsnrtowcs()depends on theLC_CTYPEcategory of the current locale. π - Passing
NULLaspsis not multithread safe. π
π₯ SEE ALSO
okay that's the whole page, mwah π this was mbsnrtowcs(3) from Linux man-pages 6.20, dated 2026-02-08. go forth and convert your bytes responsibly, bestie π§π
π¦ 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