diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-05-11 18:44:14 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-05-11 18:44:14 +0000 |
commit | 7847cf8cac3ace56d062c6d1962f2df02d25d329 (patch) | |
tree | c860a1a863e5b2697b9daf1ea627279ec05d3ced /lib/libc | |
parent | 8d8d7a1eeeb3509c69bb27b3d97c04a887175599 (diff) |
major abi changes:
* introduce the mbstate_t typedef.
impacts gnu libiconv, which has already been taken care of.
* Prepare for mb stuff to really exist, replace macro MB_CUR_MAX with
an external variable __mb_cur_max (impacts libX11 and various ports).
* use mbstate in all the mb <-> wchar functions with state.
* add a stub iswctype function allowing some ports to compile.
bash and gdiff are missing wcscoll, and need to be told there's no i18n
until this is fixed.
Discussed and matthieu, otto, millert, kettenis, deraadt.
Major libc bump
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/locale/Makefile.inc | 10 | ||||
-rw-r--r-- | lib/libc/locale/__mb_cur_max.c | 39 | ||||
-rw-r--r-- | lib/libc/locale/btowc.3 | 87 | ||||
-rw-r--r-- | lib/libc/locale/iswctype.3 | 99 | ||||
-rw-r--r-- | lib/libc/locale/iswctype_sb.c | 67 | ||||
-rw-r--r-- | lib/libc/locale/mblen.3 | 178 | ||||
-rw-r--r-- | lib/libc/locale/mbrlen.3 | 207 | ||||
-rw-r--r-- | lib/libc/locale/mbrtowc.3 | 198 | ||||
-rw-r--r-- | lib/libc/locale/mbsinit.3 | 78 | ||||
-rw-r--r-- | lib/libc/locale/mbsrtowcs.3 | 185 | ||||
-rw-r--r-- | lib/libc/locale/mbstowcs.3 | 127 | ||||
-rw-r--r-- | lib/libc/locale/mbtowc.3 | 179 | ||||
-rw-r--r-- | lib/libc/locale/multibyte_sb.c | 226 | ||||
-rw-r--r-- | lib/libc/locale/runetype.h | 25 | ||||
-rw-r--r-- | lib/libc/locale/wcrtomb.3 | 147 | ||||
-rw-r--r-- | lib/libc/locale/wcsrtombs.3 | 177 | ||||
-rw-r--r-- | lib/libc/locale/wcstombs.3 | 132 | ||||
-rw-r--r-- | lib/libc/locale/wctob.3 | 88 | ||||
-rw-r--r-- | lib/libc/locale/wctomb.3 | 131 | ||||
-rw-r--r-- | lib/libc/locale/wctype.3 | 91 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/Makefile.inc | 2 |
22 files changed, 2467 insertions, 8 deletions
diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 67edae18770..bc8bce1e538 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,12 +1,16 @@ -# $OpenBSD: Makefile.inc,v 1.6 2005/04/30 09:14:23 espie Exp $ +# $OpenBSD: Makefile.inc,v 1.7 2005/05/11 18:44:12 espie Exp $ # locale sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/locale ${LIBCSRCDIR}/locale SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ - localeconv.c nl_langinfo.c setlocale.c iswctype_sb.c + localeconv.c nl_langinfo.c setlocale.c iswctype_sb.c multibyte_sb.c \ + __mb_cur_max.c -MAN+= nl_langinfo.3 setlocale.3 iswalnum.3 towlower.3 +MAN+= nl_langinfo.3 setlocale.3 iswalnum.3 towlower.3 \ + btowc.3 mblen.3 mbrlen.3 mbrtowc.3 mbsinit.3 mbsrtowcs.3 \ + mbstowcs.3 mbtowc.3 wcrtomb.3 wcsrtombs.3 wcstombs.3 wctob.3 \ + wctomb.3 wctype.3 iswctype.3 MLINKS+=setlocale.3 localeconv.3 \ iswalnum.3 iswalpha.3 \ iswalnum.3 iswblank.3 \ diff --git a/lib/libc/locale/__mb_cur_max.c b/lib/libc/locale/__mb_cur_max.c new file mode 100644 index 00000000000..61c0d2b9c82 --- /dev/null +++ b/lib/libc/locale/__mb_cur_max.c @@ -0,0 +1,39 @@ +/* $OpenBSD: __mb_cur_max.c,v 1.1 2005/05/11 18:44:12 espie Exp $ */ +/* $NetBSD: __mb_cur_max.c,v 1.2 2001/01/25 01:25:06 itojun Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * 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 AUTHOR 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 AUTHOR 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: __mb_cur_max.c,v 1.1 2005/05/11 18:44:12 espie Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <limits.h> + +size_t __mb_cur_max = 1; +size_t __mb_len_max_runtime = MB_LEN_MAX; + diff --git a/lib/libc/locale/btowc.3 b/lib/libc/locale/btowc.3 new file mode 100644 index 00000000000..4e4fc78dbbb --- /dev/null +++ b/lib/libc/locale/btowc.3 @@ -0,0 +1,87 @@ +.\" $OpenBSD: btowc.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: btowc.3,v 1.3 2003/04/16 13:34:40 wiz Exp $ +.\" +.\" Copyright (c)2003 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 March 3, 2003 +.Dt BTOWC 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm btowc +.Nd convert a single byte character to a wide character +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wchar.h> +.Ft wint_t +.Fn btowc "int c" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn btowc +function converts a single byte character +.Fa c +in the initial shift state of the current locale to a corresponding +wide character. +.Pp +The behaviour of the +.Fn btowc +is affected by the +.Dv LC_CTYPE +category of the current locale. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +The +.Fn btowc +function returns: +.Bl -tag -width 012345678901 +.It Dv WEOF +If +.Fa c +is +.Dv EOF +or if (unsigned char) +.Fa c +does not correspond to a valid single byte character representation. +.It (otherwise) +A wide character corresponding to +.Fa c . +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +No errors are defined. +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mbrtowc 3 , +.Xr setlocale 3 , +.Xr wctob 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn btowc +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . diff --git a/lib/libc/locale/iswctype.3 b/lib/libc/locale/iswctype.3 new file mode 100644 index 00000000000..65c984cfb49 --- /dev/null +++ b/lib/libc/locale/iswctype.3 @@ -0,0 +1,99 @@ +.\" $OpenBSD: iswctype.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: iswctype.3,v 1.5 2003/04/16 13:34:40 wiz Exp $ +.\" +.\" Copyright (c)2003 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 March 4, 2003 +.Dt ISWCTYPE 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm iswctype +.Nd test a character for character class identifier +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wctype.h> +.Ft int +.Fn iswctype "wint_t wc" "wctype_t charclass" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn iswctype +function returns a boolean value that indicates whether a wide character +.Fa wc +is in +.Fa charclass . +.Pp +The behaviour of the +.Fn iswctype +is undefined if the +.Fn iswctype +function is called with an invalid +.Fa charclass +(changes of +.Dv LC_CTYPE +category invalidate +.Fa charclass ) +or invalid wide character +.Fa wc . +.Pp +The behaviour of the +.Fn iswctype +is affected by the +.Dv LC_CTYPE +category of the current locale. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +The +.Fn iswcttype +returns: +.Bl -tag -width 012345678901 +.It 0 +.Fa wc +is not in +.Fa charclass . +.It non-zero +.Fa wc +is in +.Fa charclass . +.El +.Pp +.\" ---------------------------------------------------------------------- +.Sh ERRORS +No errors are defined. +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr setlocale 3 , +.Xr towctrans 3 , +.Xr wctrans 3 , +.Xr wctype 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn iswctype +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . diff --git a/lib/libc/locale/iswctype_sb.c b/lib/libc/locale/iswctype_sb.c index 85d6cc97e9a..980735b5113 100644 --- a/lib/libc/locale/iswctype_sb.c +++ b/lib/libc/locale/iswctype_sb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iswctype_sb.c,v 1.1 2005/04/30 09:14:23 espie Exp $ */ +/* $OpenBSD: iswctype_sb.c,v 1.2 2005/05/11 18:44:12 espie Exp $ */ /* $NetBSD: iswctype_sb.c,v 1.3 2003/08/07 16:43:04 agc Exp $ */ /* @@ -36,12 +36,13 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: iswctype_sb.c,v 1.1 2005/04/30 09:14:23 espie Exp $"; +static char rcsid[] = "$OpenBSD: iswctype_sb.c,v 1.2 2005/05/11 18:44:12 espie Exp $"; #endif /* LIBC_SCCS and not lint */ #include <wchar.h> #include <wctype.h> #include <ctype.h> +#include "runetype.h" int iswalnum(wint_t c) @@ -133,3 +134,65 @@ wcwidth(wint_t c) return 1; } +static _WCTypeEntry names[] = { + "alnum", _WCTYPE_INDEX_ALNUM, + "alpha", _WCTYPE_INDEX_ALPHA, + "blank", _WCTYPE_INDEX_BLANK, + "cntrl", _WCTYPE_INDEX_CNTRL, + "digit", _WCTYPE_INDEX_DIGIT, + "graph", _WCTYPE_INDEX_GRAPH, + "lower", _WCTYPE_INDEX_LOWER, + "print", _WCTYPE_INDEX_PRINT, + "punct", _WCTYPE_INDEX_PUNCT, + "space", _WCTYPE_INDEX_SPACE, + "upper", _WCTYPE_INDEX_UPPER, + "xdigit", _WCTYPE_INDEX_XDIGIT +}; + +wctype_t +wctype(const char *charclass) +{ + int i; + + for (i = 0; i < sizeof names / sizeof names[0]; i++) + if (strcmp(names[i].te_name, charclass) == 0) + return (wctype_t)(&names[i]); + return (wctype_t)NULL; +} + +int +iswctype(wint_t c, wctype_t charclass) +{ + _WCTypeEntry *e = (_WCTypeEntry *)charclass; + if (e == NULL) { + return 0; + } + switch (e->te_mask) { + case _WCTYPE_INDEX_ALNUM: + return iswalnum(c); + case _WCTYPE_INDEX_ALPHA: + return iswalpha(c); + case _WCTYPE_INDEX_BLANK: + return iswblank(c); + case _WCTYPE_INDEX_CNTRL: + return iswcntrl(c); + case _WCTYPE_INDEX_DIGIT: + return iswdigit(c); + case _WCTYPE_INDEX_GRAPH: + return iswgraph(c); + case _WCTYPE_INDEX_LOWER: + return iswlower(c); + case _WCTYPE_INDEX_PRINT: + return iswprint(c); + case _WCTYPE_INDEX_PUNCT: + return iswpunct(c); + case _WCTYPE_INDEX_SPACE: + return iswspace(c); + case _WCTYPE_INDEX_UPPER: + return iswupper(c); + case _WCTYPE_INDEX_XDIGIT: + return iswxdigit(c); + default: + return 0; + } +} diff --git a/lib/libc/locale/mblen.3 b/lib/libc/locale/mblen.3 new file mode 100644 index 00000000000..c448689c797 --- /dev/null +++ b/lib/libc/locale/mblen.3 @@ -0,0 +1,178 @@ +.\" $OpenBSD: mblen.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mblen.3,v 1.4 2003/04/16 13:34:40 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 3, 2002 +.Dt MBLEN 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mblen +.Nd get number of bytes in a multibyte character +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <stdlib.h> +.Ft int +.Fn mblen "const char *s" "size_t n" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn mblen +function usually determines the number of bytes in +a multibyte character pointed to by +.Fa s +and returns it. +This function shall only examine max n bytes of the array beginning from +.Fa s . +.Pp +In state-dependent encodings, +.Fa s +may point the special sequence bytes to change the shift-state. +Although such sequence bytes corresponds to no individual +wide-character code, +the +.Fn mblen +changes the own state by them and treats them +as if they are a part of the subsequent multibyte character. +.Pp +Unlike +.Xr mbrlen 3 , +the first +.Fa n +bytes pointed to by +.Fa s +need to form an entire multibyte character. +Otherwise, this function causes an error. +.Pp +.Fn mblen +is equivalent to the following call, except the internal state of the +.Xr mbtowc 3 +function is not affected: +.Bd -literal -offset indent +mbtowc(NULL, s, n); +.Ed +.Pp +Calling any other functions in +.Em libc +never change the internal +state of the +.Fn mblen , +except for calling +.Xr setlocale 3 +with the +.Dv LC_CTYPE +category changed to that of the current locale. +Such +.Xr setlocale 3 +calls cause the internal state of this function to be indeterminate. +.Pp +The behaviour of +.Fn mblen +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +There are special cases: +.Bl -tag -width 0123456789 +.It "s == NULL" +.Fn mblen +initializes its own internal state to an initial state, and +determines whether the current encoding is state-dependent. +This function returns 0 if the encoding is state-independent, +otherwise non-zero. +.It "n == 0" +In this case, +the first +.Fa n +bytes of the array pointed to by +.Fa s +never form a complete character. +Thus, +.Fn mblen +always fails. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +Normally, +.Fn mblen +returns: +.Bl -tag -width 0123456789 +.It "0" +.Fa s +points to a null byte +.Pq Sq \e0 . +.It "positive" +The value returned is +a number of bytes for the valid multibyte character pointed to by +.Fa s . +There are no cases when this value is greater than +.Fa n +or the value of the +.Dv MB_CUR_MAX +macro. +.It "-1" +.Fa s +points an invalid or incomplete multibyte character. +The +.Fn mblen +also sets +.Va errno +to indicate the error. +.El +.Pp +When +.Fa s +is equal to +.Dv NULL , +.Fn mblen +returns: +.Bl -tag -width 0123456789 +.It "0" +The current encoding is state-independent. +.It "non-zero" +The current encoding is state-dependent. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +The +.Fn mblen +may causes an error in the following case: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa s +points to an invalid or incomplete multibyte character. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mbrlen 3 , +.Xr mbtowc 3 , +.Xr setlocale 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mblen +function conforms to +.St -ansiC . diff --git a/lib/libc/locale/mbrlen.3 b/lib/libc/locale/mbrlen.3 new file mode 100644 index 00000000000..e6428e60805 --- /dev/null +++ b/lib/libc/locale/mbrlen.3 @@ -0,0 +1,207 @@ +.\" $OpenBSD: mbrlen.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mbrlen.3,v 1.5 2003/09/08 17:54:31 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 3, 2002 +.Dt MBRLEN 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mbrlen +.Nd get number of bytes in a multibyte character (restartable) +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wchar.h> +.Ft int +.Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn mbrlen +function usually determines the number of bytes in +a multibyte character pointed to by +.Fa s +and returns it. +This function shall only examine max n bytes of the array beginning from +.Fa s . +.Pp +.Fn mbrlen +is equivalent to the following call (except +.Fa ps +is evaluated only once): +.Bd -literal -offset indent +mbrtowc(NULL, s, n, (ps != NULL) ? ps : &internal); +.Ed +.Pp +Here, +.Fa internal +is an internal state object. +.Pp +In state-dependent encodings, +.Fa s +may point to the special sequence bytes to change the shift-state. +Although such sequence bytes corresponds to no individual +wide-character code, these affect the conversion state object pointed to by +.Fa ps , +and the +.Fn mbrlen +treats the special sequence bytes +as if these are a part of the subsequent multibyte character. +.Pp +Unlike +.Xr mblen 3 , +.Fn mbrlen +may accept the byte sequence when it is not a complete character +but possibly contains part of a valid character. +In this case, this function will accept all such bytes +and save them into the conversion state object pointed to by +.Fa ps . +They will be used on subsequent calls of this function to restart +the conversion suspended. +.Pp +The behaviour of the +.Fn mbrlen +is affected by +.Dv LC_CTYPE +category of the current locale. +.Pp +There are the special cases: +.Bl -tag -width 0123456789 +.It "s == NULL" +.Fn mbrlen +sets the conversion state object pointed to by +.Fa ps +to an initial state and always returns 0. +Unlike +.Xr mblen 3 , +the value returned does not indicate whether the current encoding of +the locale is state-dependent. +.Pp +In this case, +.Fn mbrlen +ignores +.Fa n . +.It "n == 0" +In this case, +the first +.Fa n +bytes of the array pointed to by +.Fa s +never form a complete character. +Thus, +.Fn mbrlen +always returns (size_t)-2. +.It "ps == NULL" +.Fn mbrlen +uses its own internal state object to keep the conversion state, +instead of +.Fa ps +mentioned in this manual page. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of +.Fn mbrlen , +except for calling +.Xr setlocale 3 +with a changing +.Dv LC_CTYPE +category of the current locale. +Such +.Xr setlocale 3 +calls cause the internal state of this function to be indeterminate. +This internal state is initialized at startup time of the program. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +The +.Fn mbrlen +returns: +.Bl -tag -width 0123456789 +.It "0" +.Fa s +points to a null byte +.Pq Sq \e0 . +.It "positive" +The value returned is +a number of bytes for the valid multibyte character pointed to by +.Fa s . +There are no cases where this value is greater than +.Fa n +or the value of the +.Dv MB_CUR_MAX +macro. +.It "(size_t)-2" +.Fa s +points to the byte sequence which possibly contains part of a valid +multibyte character, but which is incomplete. +When +.Fa n +is at least +.Dv MB_CUR_MAX +can only occur if the array pointed to by +.Fa s +contains a redundant shift sequence. +.It "(size_t)-1" +.Fa s +points to an illegal byte sequence which does not form a valid multibyte +character. +In this case, +.Fn mbrtowc +sets +.Va errno +to indicate the error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn mbrlen +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa s +points to an invalid multibyte character. +.It Bq Er EINVAL +.Fa ps +points to an invalid or uninitialized mbstate_t object. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mblen 3 , +.Xr mbrtowc 3 , +.Xr setlocale 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mbrlen +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/1999 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/mbrtowc.3 b/lib/libc/locale/mbrtowc.3 new file mode 100644 index 00000000000..f8f369b7297 --- /dev/null +++ b/lib/libc/locale/mbrtowc.3 @@ -0,0 +1,198 @@ +.\" $OpenBSD: mbrtowc.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mbrtowc.3,v 1.5 2003/09/08 17:54:31 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 4, 2002 +.Dt MBRTOWC 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mbrtowc +.Nd converts a multibyte character to a wide character (restartable) +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wchar.h> +.Ft size_t +.Fn mbrtowc "wchar_t * restrict pwc" "const char * restrict s" "size_t n" \ +"mbstate_t * restrict ps" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn mbrtowc +usually converts the multibyte character pointed to by +.Fa s +to a wide character, and stores the wide character +in the wchar_t object pointed to by +.Fa pwc +if +.Fa pwc +is non-null and +.Fa s +points to a valid character. +The conversion happens in accordance with the conversion state +described in the mbstate_t object pointed to by +.Fa ps . +This function may examine at most +.Fa n +bytes of the array beginning from +.Fa s . +.Pp +If +.Fa s +points to a valid character and the character corresponds to a null wide +character, then the +.Fn mbrtowc +places the mbstate_t object pointed to by +.Fa ps +to an initial conversion state. +.Pp +Unlike +.Xr mbtowc 3 , +the +.Fn mbrtowc +may accept the byte sequence pointed to by +.Fa s +not forming a complete multibyte character +but which may be part of a valid character. +In this case, this function will accept all such bytes +and save them into the conversion state object pointed to by +.Fa ps . +They will be used at subsequent calls of this function to restart +the conversion suspended. +.Pp +The behaviour of the +.Fn mbrtowc +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +These are the special cases: +.Bl -tag -width 012345678901 +.It "s == NULL" +.Fn mbrtowc +sets the conversion state object pointed to by +.Fa ps +to an initial state and always returns 0. +Unlike +.Xr mbtowc 3 , +the value returned does not indicate whether the current encoding of +the locale is state-dependent. +.Pp +In this case, +.Fn mbrtowc +ignores +.Fa pwc +and +.Fa n , +and is equivalent to the following call: +.Bd -literal -offset indent +mbrtowc(NULL, "", 1, ps); +.Ed +.It "pwc == NULL" +The conversion from a multibyte character to a wide character has +taken place and the conversion state may be affected, but the resultant +wide character is discarded. +.It "ps == NULL" +.Fn mbrtowc +uses its own internal state object to keep the conversion state, +instead of +.Fa ps +mentioned in this manual page. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of +.Fn mbrtowc , +which is initialized at startup time of the program. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +In the usual cases, +.Fn mbrtowc +returns: +.Bl -tag -width 012345678901 +.It 0 +The next bytes pointed to by +.Fa s +form a null character. +.It positive +If +.Fa s +points to a valid character, +.Fn mbrtowc +returns the number of bytes in the character. +.It (size_t)-2 +.Fa s +points to the byte sequence which possibly contains part of a valid +multibyte character, but which is incomplete. +When +.Fa n +is at least +.Dv MB_CUR_MAX +only occurs if the array pointed to by +.Fa s +contains a redundant shift sequence. +.It (size_t)-1 +.Fa s +points to an illegal byte sequence which does not form a valid multibyte +character. +In this case, +.Fn mbrtowc +sets +.Va errno +to indicate the error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +The +.Fn mbrtowc +may causes an error in the following case: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa s +points to an invalid or incomplete multibyte character. +.It Bq Er EINVAL +.Fa ps +points to an invalid or uninitialized mbstate_t object. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mbrlen 3 , +.Xr mbtowc 3 , +.Xr setlocale 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mbrtowc +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899:1999 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/mbsinit.3 b/lib/libc/locale/mbsinit.3 new file mode 100644 index 00000000000..18fb32a3dc6 --- /dev/null +++ b/lib/libc/locale/mbsinit.3 @@ -0,0 +1,78 @@ +.\" $OpenBSD: mbsinit.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mbsinit.3,v 1.4 2003/04/16 13:34:40 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 3, 2002 +.Dt MBSINIT 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mbsinit +.Nd determines whether the state object is in initial state +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wchar.h> +.Ft int +.Fn mbsinit "const mbstate_t *ps" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +.Fn mbsinit +determines whether the state object pointed to by +.Fa ps +is in initial conversion state, or not. +.Pp +.Fa ps +may be a +.Dv NULL +pointer. +In this case, +.Fn mbsinit +will always return non-zero. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn mbsinit +returns: +.Bl -tag -width 0123456789 +.It 0 +The current state is not in initial state. +.It non-zero +The current state is in initial state or +.Fa ps +is a +.Dv NULL +pointer. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +No errors are defined. +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mbsinit +conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . diff --git a/lib/libc/locale/mbsrtowcs.3 b/lib/libc/locale/mbsrtowcs.3 new file mode 100644 index 00000000000..9d630be6397 --- /dev/null +++ b/lib/libc/locale/mbsrtowcs.3 @@ -0,0 +1,185 @@ +.\" $OpenBSD: mbsrtowcs.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mbsrtowcs.3,v 1.6 2003/09/08 17:54:31 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 4, 2002 +.Dt MBSRTOWCS 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mbsrtowcs +.Nd converts a multibyte character string to a wide character string \ +(restartable) +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wchar.h> +.Ft size_t +.Fn mbsrtowcs "wchar_t * restrict pwcs" "const char ** restrict s" "size_t n" \ +"mbstate_t * restrict ps" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn mbsrtowcs +converts the multibyte character string indirectly pointed to by +.Fa s +to the corresponding wide character string, and stores it in the +array pointed to by +.Fa pwcs . +The conversion stops due to the following reasons: +.Bl -bullet +.It +The conversion reaches a null byte. +In this case, the null byte is also converted. +.It +The +.Fn mbsrtowcs +has already stored +.Fa n +wide characters. +.It +The conversion encounters an invalid character. +.El +.Pp +Each character is converted as if +.Xr mbrtowc 3 +is continuously called. +.Pp +After conversion, +if +.Fa pwcs +is not a +.Dv NULL +pointer, +the pointer object pointed to by +.Fa s +is a +.Dv NULL +pointer (if the conversion is stopped due to reaching a null byte) +or the first byte of the character just after the last character converted. +.Pp +If +.Fa pwcs +is not a +null pointer and the conversion is stopped due to reaching +a null byte, the +.Fn mbsrtowcs +places the state object pointed to by +.Fa ps +to an initial state after the conversion has taken place. +.Pp +The behaviour of the +.Fn mbsrtowcs +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +These are the special cases: +.Bl -tag -width 012345678901 +.It "s == NULL || *s == NULL" +Undefined (may cause the program to crash). +.It "pwcs == NULL" +The conversion hass taken place, but the resultant wide character string +was discarded. +In this case, the pointer object pointed to by +.Fa s +is not modified and +.Fa n +is ignored. +.It "ps == NULL" +The +.Fn mbsrtowcs +uses its own internal state object to keep the conversion state, +instead of +.Fa ps +mentioned in this manual page. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of +.Fn mbsrtowcs , +which is initialized at startup time of the program. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn mbsrtowcs +returns: +.Bl -tag -width 012345678901 +.It 0 or positive +The value returned is the number of elements stored in the array pointed to by +.Fa pwcs , +except for a terminating null wide character (if any). +If +.Fa pwcs +is not null and the value returned is equal to +.Fa n , +the wide character string pointed to by +.Fa pwcs +is not null terminated. +If +.Fa pwcs +is a null pointer, the value returned is the number of elements to contain +the whole string converted, except for a terminating null wide character. +.It (size_t)-1 +The array indirectly pointed to by +.Fa s +contains a byte sequence forming invalid character. +In this case, +.Fn mbsrtowcs +sets +.Va errno +to indicate the error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn mbsrtowcs +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +The pointer pointed to by +.Fa s +points to an invalid or incomplete multibyte character. +.It Bq Er EINVAL +.Fa ps +points to an invalid or uninitialized mbstate_t object. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mbrtowc 3 , +.Xr mbstowcs 3 , +.Xr setlocale 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mbsrtowcs +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/1999 +.Dq Pq ISO C99 . diff --git a/lib/libc/locale/mbstowcs.3 b/lib/libc/locale/mbstowcs.3 new file mode 100644 index 00000000000..21ec9446105 --- /dev/null +++ b/lib/libc/locale/mbstowcs.3 @@ -0,0 +1,127 @@ +.\" $OpenBSD: mbstowcs.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mbstowcs.3,v 1.6 2003/09/08 17:54:31 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 3, 2002 +.Dt MBSTOWCS 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mbstowcs +.Nd converts a multibyte character string to a wide character string +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <stdlib.h> +.Ft size_t +.Fn mbstowcs "wchar_t * restrict pwcs" "const char * restrict s" "size_t n" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn mbstowcs +converts a null-terminated multibyte character string pointed to by +.Fa s +to the corresponding wide character string and stores it in the array +pointed to by +.Fa pwcs . +This function may modify the first at most +.Fa n +elements of the array pointed to by +.Fa pwcs . +Each character will be converted as if +.Xr mbtowc 3 +is continuously called, except the internal state of +.Xr mbtowc 3 +will not be affected. +.Pp +For state-dependent encoding, +.Fn mbstowcs +implies the multibyte character string pointed to by +.Fa s +always begin with an initial state. +.Pp +These are the special cases: +.Bl -tag -width 012345678901 +.It pwcs == NULL +.Fn mbstowcs +returns the number of elements to store the whole wide character string +corresponding to the multibyte character string pointed to by +.Fa s . +In this case, +.Fa n +is ignored. +.It s == NULL +Undefined (may causes the program to crash). +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn mbstowcs +returns: +.Bl -tag -width 012345678901 +.It 0 or positive +Number of elements stored in the array pointed to by +.Fa pwcs . +There are no cases where the value returned is greater than +.Fa n +(unless +.Fa pwcs +is a null pointer) or the value of the +.Dv MB_CUR_MAX +macro. +If the return value is equal to +.Fa n , +the string pointed to by +.Fa pwcs +will not be null-terminated. +.It (size_t)-1 +.Fa s +points to the string containing invalid or incomplete multibyte character. +The +.Fn mbstowcs +also sets errno to indicate the error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn mbstowcs +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa s +points to the string containing invalid or incomplete multibyte character. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mbtowc 3 , +.Xr setlocale 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mbstowcs +function conforms to +.St -ansiC . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/199 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/mbtowc.3 b/lib/libc/locale/mbtowc.3 new file mode 100644 index 00000000000..14f09e2e78f --- /dev/null +++ b/lib/libc/locale/mbtowc.3 @@ -0,0 +1,179 @@ +.\" $OpenBSD: mbtowc.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: mbtowc.3,v 1.5 2003/09/08 17:54:31 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 3, 2002 +.Dt MBTOWC 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm mbtowc +.Nd converts a multibyte character to a wide character +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <stdlib.h> +.Ft int +.Fn mbtowc "wchar_t * restrict pwc" "const char * restrict s" "size_t n" +.Sh DESCRIPTION +The +.Fn mbtowc +usually converts the multibyte character pointed to by +.Fa s +to a wide character, and stores it in the wchar_t object pointed to by +.Fa pwc +if +.Fa pwc +is non-null and +.Fa s +points to a valid character. +This function may inspect at most n bytes of the array beginning from +.Fa s . +.Pp +In state-dependent encodings, +.Fa s +may point to the special sequence bytes to change the shift-state. +Although such sequence bytes correspond to no individual +wide-character code, +.Fn mbtowc +changes its own state by the sequence bytes and treats them +as if they are a part of the subsequence multibyte character. +.Pp +Unlike +.Xr mbrtowc 3 , +the first +.Fa n +bytes pointed to by +.Fa s +need to form an entire multibyte character. +Otherwise, this function causes an error. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of the +.Fn mbtowc , +except for calling +.Xr setlocale 3 +with the +.Dv LC_CTYPE +category changed to that of the current locale. +Such +.Xr setlocale 3 +calls cause the internal state of this function to be indeterminate. +.Pp +The behaviour of +.Fn mbtowc +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +These are the special cases: +.Bl -tag -width 012345678901 +.It s == NULL +.Fn mbtowc +initializes its own internal state to an initial state, and +determines whether the current encoding is state-dependent. +This function returns 0 if the encoding is state-independent, +otherwise non-zero. +In this case, +.Fa pwc +is completely ignored. +.It pwc == NULL +.Fn mbtowc +executes the conversion as if +.Fa pwc +is non-null, but a result of the conversion is discarded. +.It n == 0 +In this case, +the first +.Fa n +bytes of the array pointed to by +.Fa s +never form a complete character. +Thus, the +.Fn mbtowc +always fails. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +Normally, +.Fn mbtowc +returns: +.Bl -tag -width 012345678901 +.It 0 +.Fa s +points to a null byte +.Pq Sq \e0 . +.It positive +Number of bytes for the valid multibyte character pointed to by +.Fa s . +There are no cases where the value returned is greater than +the value of the +.Dv MB_CUR_MAX +macro. +.It -1 +.Fa s +points to an invalid or an incomplete multibyte character. +The +.Fn mbtowc +also sets errno to indicate the error. +.El +.Pp +When +.Fa s +is equal to NULL, +.Fn mbtowc +returns: +.Bl -tag -width 0123456789 +.It 0 +The current encoding is state-independent. +.It non-zero +The current encoding is state-dependent. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn mbtowc +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa s +points to an invalid or incomplete multibyte character. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr mblen 3 , +.Xr mbrtowc 3 , +.Xr setlocale 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn mbtowc +function conforms to +.St -ansiC . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/1999 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/multibyte_sb.c b/lib/libc/locale/multibyte_sb.c new file mode 100644 index 00000000000..4ff06614b3f --- /dev/null +++ b/lib/libc/locale/multibyte_sb.c @@ -0,0 +1,226 @@ +/* $OpenBSD: multibyte_sb.c,v 1.1 2005/05/11 18:44:12 espie Exp $ */ +/* $NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $ */ + +/* + * Copyright (c) 1991 The Regents of the University of California. + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: multibyte_sb.c,v 1.1 2005/05/11 18:44:12 espie Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <errno.h> +#include <stdlib.h> +#include <wchar.h> + +/* + * Stub multibyte character functions. + * This cheezy implementation is fixed to the native single-byte + * character set. + */ + +/*ARGSUSED*/ +int +mbsinit(const mbstate_t *ps) +{ + + return 1; +} + +/*ARGSUSED*/ +size_t +mbrlen(const char *s, size_t n, mbstate_t *ps) +{ + + /* ps appears to be unused */ + + if (s == NULL || *s == '\0') + return 0; + if (n == 0) + return -1; + return 1; +} + +int +mblen(const char *s, size_t n) +{ + + /* s may be NULL */ + + return mbrlen(s, n, NULL); +} + +/*ARGSUSED*/ +size_t +mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +{ + + /* pwc may be NULL */ + /* s may be NULL */ + /* ps appears to be unused */ + + if (s == NULL) + return 0; + if (n == 0) + return -1; + if (pwc) + *pwc = (wchar_t) *s; + return (*s != '\0'); +} + +int +mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + + /* pwc may be NULL */ + /* s may be NULL */ + + return mbrtowc(pwc, s, n, NULL); +} + +/*ARGSUSED*/ +size_t +wcrtomb(char *s, wchar_t wchar, mbstate_t *ps) +{ + + /* s may be NULL */ + /* ps appears to be unused */ + + if (s == NULL) + return 0; + + *s = (char) wchar; + return 1; +} + +int +wctomb(char *s, wchar_t wchar) +{ + + /* s may be NULL */ + + return wcrtomb(s, wchar, NULL); +} + +/*ARGSUSED*/ +size_t +mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps) +{ + int count = 0; + + /* pwcs may be NULL */ + /* s may be NULL */ + /* ps appears to be unused */ + + if (!s || !*s) + return 0; + + if (n != 0) { + if (pwcs != NULL) { + do { + if ((*pwcs++ = (wchar_t) *(*s)++) == 0) + break; + count++; + } while (--n != 0); + } else { + do { + if (((wchar_t)*(*s)++) == 0) + break; + count++; + } while (--n != 0); + } + } + + return count; +} + +size_t +mbstowcs(wchar_t *pwcs, const char *s, size_t n) +{ + + /* pwcs may be NULL */ + /* s may be NULL */ + + return mbsrtowcs(pwcs, &s, n, NULL); +} + +/*ARGSUSED*/ +size_t +wcsrtombs(char *s, const wchar_t **pwcs, size_t n, mbstate_t *ps) +{ + int count = 0; + + /* s may be NULL */ + /* pwcs may be NULL */ + /* ps appears to be unused */ + + if (pwcs == NULL || *pwcs == NULL) + return (0); + + if (s == NULL) { + while (*(*pwcs)++ != 0) + count++; + return(count); + } + + if (n != 0) { + do { + if ((*s++ = (char) *(*pwcs)++) == 0) + break; + count++; + } while (--n != 0); + } + + return count; +} + +size_t +wcstombs(char *s, const wchar_t *pwcs, size_t n) +{ + + /* s may be NULL */ + /* pwcs may be NULL */ + + return wcsrtombs(s, &pwcs, n, NULL); +} + +wint_t +btowc(int c) +{ + if (c == EOF || c & ~0xFF) + return WEOF; + return (wint_t)c; +} + +int +wctob(wint_t c) +{ + if (c == WEOF || c & ~0xFF) + return EOF; + return (int)c; +} diff --git a/lib/libc/locale/runetype.h b/lib/libc/locale/runetype.h index f47d6a03129..e170ff7d4a7 100644 --- a/lib/libc/locale/runetype.h +++ b/lib/libc/locale/runetype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: runetype.h,v 1.1 2005/04/14 20:59:10 espie Exp $ */ +/* $OpenBSD: runetype.h,v 1.2 2005/05/11 18:44:12 espie Exp $ */ #ifndef _NB_RUNETYPE_H_ #define _NB_RUNETYPE_H_ @@ -8,4 +8,27 @@ typedef uint32_t __nbrune_t; +typedef uint32_t _RuneType; + +/* + * wctype stuffs. + */ +typedef struct _WCTypeEntry { + char *te_name; + _RuneType te_mask; +} _WCTypeEntry; +#define _WCTYPE_INDEX_ALNUM 0 +#define _WCTYPE_INDEX_ALPHA 1 +#define _WCTYPE_INDEX_BLANK 2 +#define _WCTYPE_INDEX_CNTRL 3 +#define _WCTYPE_INDEX_DIGIT 4 +#define _WCTYPE_INDEX_GRAPH 5 +#define _WCTYPE_INDEX_LOWER 6 +#define _WCTYPE_INDEX_PRINT 7 +#define _WCTYPE_INDEX_PUNCT 8 +#define _WCTYPE_INDEX_SPACE 9 +#define _WCTYPE_INDEX_UPPER 10 +#define _WCTYPE_INDEX_XDIGIT 11 +#define _WCTYPE_NINDEXES 12 + #endif diff --git a/lib/libc/locale/wcrtomb.3 b/lib/libc/locale/wcrtomb.3 new file mode 100644 index 00000000000..d1845fdbd25 --- /dev/null +++ b/lib/libc/locale/wcrtomb.3 @@ -0,0 +1,147 @@ +.\" $OpenBSD: wcrtomb.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: wcrtomb.3,v 1.4 2003/09/08 17:54:31 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 4, 2002 +.Dt WCRTOMB 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm wcrtomb +.Nd converts a wide character to a multibyte character (restartable) +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wchar.h> +.Ft size_t +.Fn wcrtomb "const char * restrict s" "wchar_t wc" "mbstate_t * restrict ps" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +.Fn wcrtomb +converts the wide character given by +.Fa wc +to the corresponding multibyte character, and stores it in the array +pointed to by +.Fa s +unless +.Fa s +is a null pointer. +This function will modify the first at most +.Dv MB_CUR_MAX +bytes of the array pointed by +.Fa s . +.Pp +The behaviour of +.Fn wcrtomb +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +These are the special cases: +.Bl -tag -width 012345678901 +.It "wc == 0" +For state-dependent encodings, +.Fn wcrtomb +stores a null byte preceded by a special byte sequence (if any) +to return to an initial state to the array pointed by +.Fa s , +and the state object pointed by +.Fa ps +also returned to a initial state. +.It "s == NULL" +.Fn wcrtomb +just places +.Fa ps +into a initial state. +It is equivalent to the following call: +.Bd -literal -offset indent +wcrtomb(buf, L'\\0', ps); +.Ed +.Pp +Here, +.Fa buf +is a dummy buffer. +In this case, +.Fa wc +is ignored. +.It "ps == NULL" +.Fn mbrtowc +uses its own internal state object to keep the conversion state, +instead of +.Fa ps +mentioned in this manual page. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of +.Fn mbrtowc , +which is initialized at startup time of the program. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn wcrtomb +returns: +.Bl -tag -width 012345678901 +.It "positive" +The number of bytes (including any shift sequences) +which are stored in the array. +.It "(size_t)-1" +.Fa wc +is not a valid wide character. +In this case, +.Fn wcrtomb +also sets +.Va errno +to indicate error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn wcrtomb +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa wc +is not a valid wide character. +.It Bq Er EINVAL +.Fa ps +points to an invalid or uninitialized mbstate_t object. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr setlocale 3 , +.Xr wctomb 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn wcrtomb +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C90, Amendment 1 . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/1999 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/wcsrtombs.3 b/lib/libc/locale/wcsrtombs.3 new file mode 100644 index 00000000000..f75faa19739 --- /dev/null +++ b/lib/libc/locale/wcsrtombs.3 @@ -0,0 +1,177 @@ +.\" $OpenBSD: wcsrtombs.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: wcsrtombs.3,v 1.6 2003/09/08 17:54:32 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 4, 2002 +.Dt WCSRTOMBS 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm wcsrtombs +.Nd converts a wide character string to a multibyte character string \ +(restartable) +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <stdlib.h> +.Ft size_t +.Fn wcsrtombs "const char * restrict s" "const wchar_t ** restrict pwcs" \ +"size_t n" "mbstate_t * restrict ps" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn wcsrtombs +converts the null-terminated wide character string indirectly pointed to by +.Fa pwcs +to the corresponding multibyte character string, +and store it to the array pointed to by +.Fa s . +The conversion stops due to the following reasons: +.Bl -bullet +.It +The conversion reaches a null wide character. +In this case, the null wide character is also converted. +.It +The +.Fn wcsrtombs +has already stored +.Fa n +bytes to the array pointed to by +.Fa s . +.It +The conversion encounters an invalid character. +.El +.Pp +Each characters will be converted as if +.Xr wcrtomb 3 +is continuously called, except the internal state of +.Xr wcrtomb 3 +will not be affected. +.Pp +After conversion, +if +.Fa s +is not a +.Dv NULL +pointer, +the pointer object pointed to by +.Fa pwcs +is a +.Dv NULL +pointer (if the conversion is stopped due to reaching a null wide character) +or the first byte of the character just after the last character converted. +.Pp +If +.Fa s +is not a null pointer and the conversion is stopped due to reaching +a null wide character, the +.Fn wcsrtombs +places the state object pointed to by +.Fa ps +to an initial state after the conversion is taken place. +.Pp +The behaviour of the +.Fn wcsrtombs +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +These are the special cases: +.Bl -tag -width 012345678901 +.It "s == NULL" +.Fn wcsrtombs +returns the number of bytes to store the whole multibyte character string +corresponding to the wide character string pointed to by +.Fa pwcs , +not including the terminating null byte. +In this case, +.Fa n +is ignored. +.It "pwcs == NULL || *pwcs == NULL" +Undefined (may causes the program to crash). +.It "ps == NULL" +.Fn wcsrtombs +uses its own internal state object to keep the conversion state, +instead of +.Fa ps +mentioned in this manual page. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of +.Fn wcsrtombs , +that is initialized at startup time of the program. +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn wcsrtombs +returns: +.Bl -tag -width 012345678901 +.It 0 or positive +Number of bytes stored to the array pointed to by +.Fa s , +except for a null byte. +There is no cases that the value returned is greater than +.Fa n +(unless +.Fa s +is a null pointer). +If the return value is equal to +.Fa n , +the string pointed to by +.Fa s +will not be null-terminated. +.It (size_t)-1 +.Fa pwcs +points to the string containing invalid wide character. +The +.Fn wcsrtombs +also sets errno to indicate the error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn wcsrtombs +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa pwcs +points to the string containing an invalid wide character. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr setlocale 3 , +.Xr wcrtomb 3 , +.Xr wcstombs 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn wcsrtombs +function conforms to +.St -ansiC . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/AMD1:1995 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/wcstombs.3 b/lib/libc/locale/wcstombs.3 new file mode 100644 index 00000000000..e4a5fc9fff0 --- /dev/null +++ b/lib/libc/locale/wcstombs.3 @@ -0,0 +1,132 @@ +.\" $OpenBSD: wcstombs.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: wcstombs.3,v 1.5 2003/09/08 17:54:32 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 4, 2002 +.Dt WCSTOMBS 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm wcstombs +.Nd converts a wide character string to a multibyte character string +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <stdlib.h> +.Ft size_t +.Fn wcstombs "const char * restrict s" "wchar_t * restrict pwcs" "size_t n" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +.Fn wcstombs +converts the null-terminated wide character string pointed to by +.Fa pwcs +to the corresponding multibyte character string, +and stores it in the array pointed to by +.Fa s . +This function may modify the first at most +.Fa n +bytes of the array pointed to by +.Fa s . +Each character will be converted as if +.Xr wctomb 3 +is continuously called, except the internal state of +.Xr wctomb 3 +will not be affected. +.Pp +For state-dependent encoding, the +.Fn wcstombs +implies the result multibyte character string pointed to by +.Fa s +always to begin with an initial state. +.Pp +The behaviour of the +.Fn wcstombs +is affected by the +.Dv LC_CTYPE +category of the current locale. +.Pp +There are special cases: +.Bl -tag -width 012345678901 +.It s == NULL +The +.Fn wcstombs +returns the number of bytes to store the whole multibyte character string +corresponding to the wide character string pointed to by +.Fa pwcs . +In this case, +.Fa n +is ignored. +.It pwcs == NULL +Undefined (may causes the program to crash). +.El +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn wcstombs +returns: +.Bl -tag -width 012345678901 +.It 0 or positive +Number of bytes stored in the array pointed to by +.Fa s . +There are no cases that the value returned is greater than +.Fa n +(unless +.Fa s +is a null pointer). +If the return value is equal to +.Fa n , +the string pointed to by +.Fa s +will not be null-terminated. +.It (size_t)-1 +.Fa pwcs +points the string containing invalid wide character. +.Fn wcstombs +also sets +.Va errno +to indicate the error. +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +.Fn wcstombs +may cause an error in the following cases: +.Bl -tag -width Er +.It Bq Er EILSEQ +.Fa pwcs +Points to the string containing invalid wide character. +.El +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr setlocale 3 , +.Xr wctomb 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn wcstombs +function conforms to +.St -ansiC . +The restrict qualifier is added at +.\" .St -isoC99 . +ISO/IEC 9899/1999 +.Pq Dq ISO C99 . diff --git a/lib/libc/locale/wctob.3 b/lib/libc/locale/wctob.3 new file mode 100644 index 00000000000..191568b5d71 --- /dev/null +++ b/lib/libc/locale/wctob.3 @@ -0,0 +1,88 @@ +.\" $OpenBSD: wctob.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: wctob.3,v 1.3 2003/04/16 13:34:41 wiz Exp $ +.\" +.\" Copyright (c)2003 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 March 3, 2003 +.Dt WCTOB 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm wctob +.Nd convert a wide character to a single byte character +.\" ---------------------------------------------------------------------- +.Sh LIBRARY +.Lb libc +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.In wchar.h +.Ft int +.Fn wctob "wint_t wc" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn wctob +function converts a wide character +.Fa wc +to a corresponding single byte character in the initial shift state of +the current locale. +.Pp +The behaviour of the +.Fn wctob +is affected by the +.Dv LC_CTYPE +category of the current locale. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +The +.Fn wctob +function returns: +.Bl -tag -width 012345678901 +.It Dv EOF +if +.Fa wc +is +.Dv WEOF +or if +.Fa wc +does not correspond to a valid single byte character representation. +.It (otherwise) +a single byte character corresponding to +.Fa wc . +.El +.\" ---------------------------------------------------------------------- +.Sh ERRORS +No errors are defined. +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr btowc 3 , +.Xr setlocale 3 , +.Xr wcrtomb 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn wctob +function conforms to +.St -isoC-amd1 . diff --git a/lib/libc/locale/wctomb.3 b/lib/libc/locale/wctomb.3 new file mode 100644 index 00000000000..758a2962bc6 --- /dev/null +++ b/lib/libc/locale/wctomb.3 @@ -0,0 +1,131 @@ +.\" $OpenBSD: wctomb.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: wctomb.3,v 1.3 2003/04/16 13:34:41 wiz Exp $ +.\" +.\" Copyright (c)2002 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 February 3, 2002 +.Dt WCTOMB 3 +.Os +.Sh NAME +.Nm wctomb +.Nd converts a wide character to a multibyte character +.Sh SYNOPSIS +.Fd #include <stdlib.h> +.Ft int +.Fn wctomb "char * s" "const wchar_t wchar" +.Sh DESCRIPTION +The +.Fn wctomb +converts the wide character +.Fa wchar +to the corresponding multibyte character, and stores it in the array +pointed to by +.Fa s . +.Fn wctomb +may store at most +.Dv MB_CUR_MAX +bytes in the array. +.Pp +In state-dependent encoding, +.Fn wctomb +may store the special sequence to change the conversion state +before an actual multibyte character into the array pointed to by +.Fa s . +If +.Fa wchar +is a null wide character +.Pq Sq \e0 , +this function places its own internal state to an initial conversion state. +.Pp +Calling any other functions in +.Em libc +never change the internal +state of +.Fn wctomb , +except for calling +.Xr setlocale 3 +with the +.Dv LC_CTYPE +category changed to that of the current locale. +Such +.Xr setlocale 3 +calls cause the internal state of this function to be indeterminate. +.Pp +The behaviour of +.Fn wctomb +is affected by +.Dv LC_CTYPE +category of the current locale. +.Pp +There is a special case: +.Bl -tag -width 012345678901 +.It s == NULL +.Fn wctomb +initializes its own internal state to an initial state, and +determines whether the current encoding is state-dependent. +This function returns 0 if the encoding is state-independent, +otherwise non-zero. +In this case, +.Fa wchar +is completely ignored. +.El +.Sh RETURN VALUES +Normally, +.Fn wctomb +returns: +.Bl -tag -width 012345678901 +.It positive +Number of bytes for the valid multibyte character pointed to by +.Fa s . +There are no cases where the value returned is greater than +.Fa n +or the value of the +.Dv MB_CUR_MAX macro . +.It -1 +.Fa wchar +is an invalid wide character. +.El +.Pp +If +.Fa s +is equal to +.Dv NULL , +.Fn mbtowc +returns: +.Bl -tag -width 0123456789 +.It 0 +The current encoding is state-independent. +.It non-zero +The current encoding is state-dependent. +.El +.Sh ERRORS +No errors are defined. +.Sh SEE ALSO +.Xr setlocale 3 +.Sh STANDARDS +The +.Fn wctomb +function conforms to +.St -ansiC . diff --git a/lib/libc/locale/wctype.3 b/lib/libc/locale/wctype.3 new file mode 100644 index 00000000000..74a042dd652 --- /dev/null +++ b/lib/libc/locale/wctype.3 @@ -0,0 +1,91 @@ +.\" $OpenBSD: wctype.3,v 1.1 2005/05/11 18:44:12 espie Exp $ +.\" $NetBSD: wctype.3,v 1.4 2003/04/16 13:34:41 wiz Exp $ +.\" +.\" Copyright (c)2003 Citrus Project, +.\" 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 AUTHOR 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 AUTHOR 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 March 4, 2003 +.Dt WCTYPE 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm wctype +.Nd get character class identifier by name +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.Fd #include <wctype.h> +.Ft wctype_t +.Fn wctype "const char *charclass" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn wctype +function returns a character class identifier corresponding to the +locale-specific character class name +.Fa charclass . +This identifier can be used in subsequent calls of +.Fn iswctype . +The following names are defined in all locales: +.Bd -literal -offset indent +alnum alpha blank cntrl digit graph +lower print punct space upper xdigit +.Ed +.Pp +The behaviour of +.Fn wctype +is affected by the +.Dv LC_CTYPE +category of the current locale. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn wcttype +returns: +.Bl -tag -width 012345678901 +.It 0 +If +.Fa charclass +does not correspond to a valid character class name. +.It non-zero +A character class identifier corresponding to +.Fa charclass . +.El +.Pp +Note: wctype_t is a scalar type, e.g., a pointer. +.\" ---------------------------------------------------------------------- +.Sh ERRORS +No errors are defined. +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr iswctype 3 , +.Xr setlocale 3 , +.Xr towctrans 3 , +.Xr wctrans 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn wctype +function conforms to +.\" .St -isoC-amd1 . +ISO/IEC 9899/AMD1:1995 +.Pq Sq ISO C90, Amendment 1 . diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index ca182c4511c..fbdb2500180 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ -major=36 +major=37 minor=0 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then libpthread must also be updated. diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index 1d5ba5c9bd4..ba81d5ee087 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -6,7 +6,7 @@ SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c atoll.c bsearch.c \ calloc.c cfree.c exit.c ecvt.c gcvt.c getenv.c getopt_long.c \ getsubopt.c hcreate.c heapsort.c l64a.c llabs.c lsearch.c malloc.c \ - merge.c multibyte.c putenv.c qsort.c radixsort.c rand.c random.c \ + merge.c putenv.c qsort.c radixsort.c rand.c random.c \ realpath.c setenv.c strtod.c strtol.c strtoll.c strtonum.c strtoul.c \ strtoull.c system.c \ tfind.c tsearch.c _rand48.c drand48.c erand48.c jrand48.c lcong48.c \ |