c32rtomb.3 revision 1.2 $NetBSD: c32rtomb.3,v 1.2 2024/08/15 14:58:00 riastradh Exp $ Copyright (c) 2024 The NetBSD Foundation, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..Dd August 14, 2024
.Dt C32RTOMB 3
.Os
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""".Sh NAME
.Nm c32rtomb
.Nd Restartable UTF-32 code unit to multibyte conversion
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""".Sh LIBRARY
.Lb libc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""".Sh SYNOPSIS
n uchar.h .Ft size_t
.Fn c32rtomb "char * restrict s" \
"char32_t c32" \
"mbstate_t * restrict ps"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""".Sh DESCRIPTION
The
.Nm
function attempts to encode Unicode input as a multibyte character
sequence output at
.Fa s
in the current locale, writing anywhere between zero and
.Dv MB_CUR_MAX
bytes, inclusive, to
.Fa s ,
depending on the inputs and conversion state
.Fa ps .
p
The input
.Fa c32
is a UTF-32 code unit, which represents a single Unicode scalar value,
i.e., a Unicode code point that is not in the interval [0xd800,0xdfff]
of surrogate code points.
p
If a surrogate code point is passed,
.Nm
will return
.Li (size_t)-1
to denote failure with
.Xr errno 2
set to
.Er EILSEQ .
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh RETURN VALUES
The
.Nm
function returns the number of bytes written to
.Fa s
on success, or sets
.Xr errno 2
and returns
.Li "(size_t)-1"
on failure.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh EXAMPLES
Convert a sequence of Unicode scalar values to a multibyte sequence,
NUL-terminate it, and print it:
d -literal -offset indent char32_t c32[] = { 0x1f4a9, 0x20ac, 0x21 };
char buf[__arraycountb(c32)*MB_CUR_MAX + 1], *s = buf;
size_t i;
mbstate_t mbs = {0}; /* initial conversion state */
for (i = 0; i < __arraycount(c32); i++) {
size_t len;
len = c32rtomb(s, c32[i], &mbs);
if (len == (size_t)-1)
err(1, "c32rtomb");
assert(len < sizeof(buf) - (s - buf));
s += len;
}
*s = '\e0'; /* NUL-terminate */
printf("%s\en", buf);
.Ed
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh ERRORS
l -tag -width ".Bq Er EILSEQ" t Bq Er EILSEQ A surrogate code point was passed as
.Fa c32 .
t Bq Er EILSEQ The Unicode scalar value requested cannot be encoded as a multibyte
sequence in the current locale.
t Bq Er EIO An error occurred in loading the locale's character conversions.
.El
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh SEE ALSO
.Xr c16rtomb 3 ,
.Xr mbrtoc16 3 ,
.Xr mbrtoc32 3 ,
.Xr uchar 3
.Rs
.%B The Unicode Standard
.%O Version 15.0 \(em Core Specification
.%Q The Unicode Consortium
.%D September 2022
.%U https://www.unicode.org/versions/Unicode15.0.0/UnicodeStandard-15.0.pdf
.Re
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh STANDARDS
The
.Nm
function conforms to
.St -isoC-2011 .
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh HISTORY
The
.Nm
function first appeared in
.Nx 11.0 .