MirBSD manpage: wcrtomb(3)

WCRTOMB(3)                 BSD Programmer's Manual                  WCRTOMB(3)


     wcrtomb - converts a wide character to a multibyte character (restart-


     #include <wchar.h>

     wcrtomb(char * restrict s, wchar_t wc, mbstate_t * restrict ps);


     wcrtomb() converts the wide character given by wc to the corresponding
     multibyte character, and stores it in the array pointed to by s unless s
     is a null pointer. This function will modify the first at most MB_CUR_MAX
     bytes of the array pointed by s.

     The behaviour of wcrtomb() is affected by the LC_CTYPE category of the
     current locale.

     These are the special cases:

     wc == 0       For state-dependent encodings, wcrtomb() stores a null byte
                   preceded by a special byte sequence (if any) to return to
                   an initial state to the array pointed by s, and the state
                   object pointed by ps also returned to a initial state.

     s == NULL     wcrtomb() just places ps into a initial state. It is
                   equivalent to the following call:

                         wcrtomb(buf, L'\0', ps);

                   Here, buf is a dummy buffer. In this case, wc is ignored.

     ps == NULL    mbrtowc() uses its own internal state object to keep the
                   conversion state, instead of ps mentioned in this manual

                   Calling any other functions in libc never changes the
                   internal state of wcrtomb(), which is initialised at start-
                   up time of the program.


     wcrtomb() returns:

     positive      The number of bytes (including any shift sequences) which
                   are stored in the array.

     (size_t)-1    wc is not a valid wide character. In this case, wcrtomb()
                   also sets errno to indicate error.


     wcrtomb() may cause an error in the following cases:

     [EILSEQ]      wc is not a valid wide character.

     [EINVAL]      ps points to an invalid or uninitialised mbstate_t object.


     iswoctet(3), optu8to16(3), setlocale(3), wctomb(3)


     The wcrtomb() function conforms to ISO/IEC 9899/AMD1:1995 ("ISO C90,
     Amendment 1").

     At present, MirBSD is limited to the UCS BMP (Basic Multilingual Plane),
     thus OPTU-8 is limited to the common subset of CESU-8 and UTF-8.


     Thorsten Glaser <tg@mirbsd.de> wrote the entire internationalisation im-
     plementation in MirBSD. He is also the steward for the OPTU encoding.


     On a system whose wide character type is only 16 bits wide, as opposed to
     31 bits of ISO 10646, the OPTU encoder and decoder are permitted to not
     de- and recompose any surrogates encountered and pass them through as if
     they were regular wide characters with no special function. Since MirBSD
     is such a system, the reference implementation does not care about UTF-16
     surrogates (U+D800 to U+DFFF) posing as OPTU-16 characters at all; a
     planes-aware Universal Coded Character Set-using application is required
     to handle surrogates by itself. For compatibility purposes, wcrtomb
     should always be assumed to not treat surrogates specially; applications
     must ensure to not produce invalid surrogates unless limited to the BMP.

     optu16to8() does, however, correctly reject the codepoints U+FFFE and
     U+FFFF as invalid.

MirBSD #10-current            December 11, 2021                              1

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung