diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-07-01 08:59:28 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-07-01 08:59:28 +0000 |
commit | ae36f7fa11ba3a91c7f8fb688683282a5042d5b7 (patch) | |
tree | 3652c6a307ff32345fe09ba7a76cc27744f3731f | |
parent | 0d1d2004c203fa5a7aaf53d54981e8396c7068de (diff) |
Add a few missing functions so that wctype.h/wchar.h are more or less
uptodate, namely, wcsto(u)l(l) family, wcstod, stubs from wctrans/towctrans
crank minor.
okay millert@, jmc@.
-rw-r--r-- | include/wchar.h | 21 | ||||
-rw-r--r-- | include/wctype.h | 8 | ||||
-rw-r--r-- | lib/libc/locale/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/locale/_wcstol.h | 136 | ||||
-rw-r--r-- | lib/libc/locale/_wcstoul.h | 116 | ||||
-rw-r--r-- | lib/libc/locale/iswctype_sb.c | 35 | ||||
-rw-r--r-- | lib/libc/locale/runetype.h | 15 | ||||
-rw-r--r-- | lib/libc/locale/towctrans.3 | 86 | ||||
-rw-r--r-- | lib/libc/locale/wcstod.c | 126 | ||||
-rw-r--r-- | lib/libc/locale/wcstol.c | 22 | ||||
-rw-r--r-- | lib/libc/locale/wcstoll.c | 22 | ||||
-rw-r--r-- | lib/libc/locale/wcstoul.c | 21 | ||||
-rw-r--r-- | lib/libc/locale/wcstoull.c | 21 | ||||
-rw-r--r-- | lib/libc/locale/wctoint.h | 79 | ||||
-rw-r--r-- | lib/libc/locale/wctrans.3 | 88 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 |
16 files changed, 792 insertions, 12 deletions
diff --git a/include/wchar.h b/include/wchar.h index 82db7449361..161d1b2f5c1 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wchar.h,v 1.5 2005/06/20 10:46:34 espie Exp $ */ +/* $OpenBSD: wchar.h,v 1.6 2005/07/01 08:59:27 espie Exp $ */ /* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */ /*- @@ -134,6 +134,7 @@ size_t wcsspn(const wchar_t *, const wchar_t *); wchar_t *wcsstr(const wchar_t *, const wchar_t *); wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, wchar_t ** __restrict); +size_t wcsxfrm(wchar_t *, const wchar_t *, size_t); wchar_t *wcswcs(const wchar_t *, const wchar_t *); wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); int wmemcmp(const wchar_t *, const wchar_t *, size_t); @@ -144,9 +145,25 @@ wchar_t *wmemset(wchar_t *, wchar_t, size_t); size_t wcslcat(wchar_t *, const wchar_t *, size_t); size_t wcslcpy(wchar_t *, const wchar_t *, size_t); +int wcswidth(const wchar_t *, size_t); int wctob(wint_t); int wcscoll(const wchar_t *, const wchar_t *); -size_t wcsxfrm(wchar_t *, const wchar_t *, size_t); +int wcwidth(wchar_t); + +double wcstod(const wchar_t * __restrict, wchar_t ** __restrict); +long int wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int base); +unsigned long int wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, + int base); + +#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ + defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) > 199901L +/* LONGLONG */ +long long int wcstoll(const wchar_t * __restrict, + wchar_t ** __restrict, int base); +/* LONGLONG */ +unsigned long long int wcstoull(const wchar_t * __restrict, + wchar_t ** __restrict, int base); +#endif wint_t ungetwc(wint_t, FILE *); wint_t fgetwc(FILE *); diff --git a/include/wctype.h b/include/wctype.h index e8058e62d54..051c2730a1b 100644 --- a/include/wctype.h +++ b/include/wctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wctype.h,v 1.3 2005/05/11 18:44:12 espie Exp $ */ +/* $OpenBSD: wctype.h,v 1.4 2005/07/01 08:59:27 espie Exp $ */ /* $NetBSD: wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */ /*- @@ -67,10 +67,12 @@ int iswpunct(wint_t); int iswspace(wint_t); int iswupper(wint_t); int iswxdigit(wint_t); +int iswctype(wint_t, wctype_t); +wint_t towctrans(wint_t, wctrans_t); wint_t towlower(wint_t); wint_t towupper(wint_t); -int iswctype(wint_t, wctype_t); -wctype_t wctype(const char *); +wctrans_t wctrans(const char *); +wctype_t wctype(const char *); __END_DECLS #endif /* _WCTYPE_H_ */ diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index bc8bce1e538..da965f5a11d 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,16 +1,16 @@ -# $OpenBSD: Makefile.inc,v 1.7 2005/05/11 18:44:12 espie Exp $ +# $OpenBSD: Makefile.inc,v 1.8 2005/07/01 08:59:27 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 multibyte_sb.c \ - __mb_cur_max.c + __mb_cur_max.c wcstod.c wcstol.c wcstoul.c wcstoll.c wcstoull.c 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 + wctomb.3 wctype.3 iswctype.3 wctrans.3 towctrans.3 MLINKS+=setlocale.3 localeconv.3 \ iswalnum.3 iswalpha.3 \ iswalnum.3 iswblank.3 \ diff --git a/lib/libc/locale/_wcstol.h b/lib/libc/locale/_wcstol.h new file mode 100644 index 00000000000..7b49bbff27a --- /dev/null +++ b/lib/libc/locale/_wcstol.h @@ -0,0 +1,136 @@ +/* $OpenBSD: _wcstol.h,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: _wcstol.h,v 1.2 2003/08/07 16:43:03 agc Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * 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. + * + * Original version ID: + * @(#)strtol.c 8.1 (Berkeley) 6/4/93 + * NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp + * Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp + */ + +/* + * function template for wcstol, wcstoll and wcstoimax. + * + * parameters: + * FUNCNAME : function name + * int_type : return type + * MIN_VALUE : lower limit of the return type + * MAX_VALUE : upper limit of the return type + */ + +int_type +FUNCNAME(const wchar_t *nptr, wchar_t **endptr, int base) +{ + const wchar_t *s; + int_type acc, cutoff; + wint_t wc; + int i; + int neg, any, cutlim; + + /* check base value */ + if (base && (base < 2 || base > 36)) { + errno = EINVAL; + return 0; + } + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + wc = (wchar_t) *s++; + } while (iswspace(wc)); + if (wc == L'-') { + neg = 1; + wc = *s++; + } else { + neg = 0; + if (wc == L'+') + wc = *s++; + } + if ((base == 0 || base == 16) && + wc == L'0' && (*s == L'x' || *s == L'X')) { + wc = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = wc == L'0' ? 8 : 10; + + /* + * See strtol for comments as to the logic used. + */ + cutoff = neg ? MIN_VALUE : MAX_VALUE; + cutlim = (int)(cutoff % base); + cutoff /= base; + if (neg) { + if (cutlim > 0) { + cutlim -= base; + cutoff += 1; + } + cutlim = -cutlim; + } + for (acc = 0, any = 0;; wc = (wchar_t) *s++) { + i = wctoint(wc); + if (i == -1) + break; + if (i >= base) + break; + if (any < 0) + continue; + if (neg) { + if (acc < cutoff || (acc == cutoff && i > cutlim)) { + any = -1; + acc = MIN_VALUE; + errno = ERANGE; + } else { + any = 1; + acc *= base; + acc -= i; + } + } else { + if (acc > cutoff || (acc == cutoff && i > cutlim)) { + any = -1; + acc = MAX_VALUE; + errno = ERANGE; + } else { + any = 1; + acc *= base; + acc += i; + } + } + } + if (endptr != 0) + /* LINTED interface specification */ + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/lib/libc/locale/_wcstoul.h b/lib/libc/locale/_wcstoul.h new file mode 100644 index 00000000000..736b38fbeab --- /dev/null +++ b/lib/libc/locale/_wcstoul.h @@ -0,0 +1,116 @@ +/* $OpenBSD: _wcstoul.h,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: _wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp $ */ + +/* + * Copyright (c) 1990, 1993 + * 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. + * + * Original version ID: + * @(#)strtoul.c 8.1 (Berkeley) 6/4/93 + * Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp + * NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp + */ + +/* + * function template for wcstoul, wcstoull and wcstoumax. + * + * parameters: + * FUNCNAME : function name + * uint_type : return type + * MAX_VALUE : upper limit of the return type + */ + +uint_type +FUNCNAME(const wchar_t *nptr, wchar_t **endptr, int base) +{ + const wchar_t *s; + uint_type acc, cutoff; + wint_t wc; + int i; + int neg, any, cutlim; + + if (base && (base < 2 || base > 36)) { + errno = EINVAL; + return 0; + } + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + wc = (wchar_t) *s++; + } while (iswspace(wc)); + if (wc == L'-') { + neg = 1; + wc = *s++; + } else { + neg = 0; + if (wc == L'+') + wc = *s++; + } + if ((base == 0 || base == 16) && + wc == L'0' && (*s == L'x' || *s == L'X')) { + wc = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = wc == L'0' ? 8 : 10; + + /* + * See strtoul for comments as to the logic used. + */ + cutoff = MAX_VALUE / (uint_type)base; + cutlim = (int)(MAX_VALUE % (uint_type)base); + for (acc = 0, any = 0;; wc = (wchar_t) *s++) { + i = wctoint(wc); + if (i == (wint_t)-1) + break; + if (i >= base) + break; + if (any < 0) + continue; + if (acc > cutoff || (acc == cutoff && i > cutlim)) { + any = -1; + acc = MAX_VALUE; + errno = ERANGE; + } else { + any = 1; + acc *= (uint_type)base; + acc += i; + } + } + if (neg && any > 0) + acc = -acc; + if (endptr != 0) + /* LINTED interface specification */ + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/lib/libc/locale/iswctype_sb.c b/lib/libc/locale/iswctype_sb.c index 980735b5113..1bf75a3cb85 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.2 2005/05/11 18:44:12 espie Exp $ */ +/* $OpenBSD: iswctype_sb.c,v 1.3 2005/07/01 08:59:27 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.2 2005/05/11 18:44:12 espie Exp $"; +static char rcsid[] = "$OpenBSD: iswctype_sb.c,v 1.3 2005/07/01 08:59:27 espie Exp $"; #endif /* LIBC_SCCS and not lint */ #include <wchar.h> #include <wctype.h> #include <ctype.h> +#include <errno.h> #include "runetype.h" int @@ -149,6 +150,12 @@ static _WCTypeEntry names[] = { "xdigit", _WCTYPE_INDEX_XDIGIT }; +static _WCTransEntry tnames[] = { + "tolower", 0, 0, + "toupper", 0, 0 +}; + + wctype_t wctype(const char *charclass) { @@ -160,6 +167,17 @@ wctype(const char *charclass) return (wctype_t)NULL; } +wctrans_t +wctrans(const char *charclass) +{ + int i; + + for (i = 0; i < sizeof tnames / sizeof tnames[0]; i++) + if (strcmp(names[i].te_name, charclass) == 0) + return (wctrans_t)(&tnames[i]); + return (wctrans_t)NULL; +} + int iswctype(wint_t c, wctype_t charclass) { @@ -196,3 +214,16 @@ iswctype(wint_t c, wctype_t charclass) return 0; } } + +wint_t +towctrans(wint_t c, wctrans_t desc) +{ + if (desc == (wctrans_t)(&tnames[_WCTRANS_INDEX_LOWER])) { + return towlower(c); + } else if (desc == (wctrans_t)(&tnames[_WCTRANS_INDEX_UPPER])) { + return towupper(c); + } else { + errno = EINVAL; + return (c); + } +} diff --git a/lib/libc/locale/runetype.h b/lib/libc/locale/runetype.h index e170ff7d4a7..b65b76273e1 100644 --- a/lib/libc/locale/runetype.h +++ b/lib/libc/locale/runetype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: runetype.h,v 1.2 2005/05/11 18:44:12 espie Exp $ */ +/* $OpenBSD: runetype.h,v 1.3 2005/07/01 08:59:27 espie Exp $ */ #ifndef _NB_RUNETYPE_H_ #define _NB_RUNETYPE_H_ @@ -11,6 +11,19 @@ typedef uint32_t __nbrune_t; typedef uint32_t _RuneType; /* + * wctrans stuffs. + */ +typedef struct _WCTransEntry { + char *te_name; + __nbrune_t *te_cached; + void *te_extmap; +} _WCTransEntry; + +#define _WCTRANS_INDEX_LOWER 0 +#define _WCTRANS_INDEX_UPPER 1 +#define _WCTRANS_NINDEXES 2 + +/* * wctype stuffs. */ typedef struct _WCTypeEntry { diff --git a/lib/libc/locale/towctrans.3 b/lib/libc/locale/towctrans.3 new file mode 100644 index 00000000000..26bafdb9780 --- /dev/null +++ b/lib/libc/locale/towctrans.3 @@ -0,0 +1,86 @@ +.\" $OpenBSD: towctrans.3,v 1.1 2005/07/01 08:59:27 espie Exp $ +.\" +.\" $NetBSD: towctrans.3,v 1.5 2004/01/24 16:58:54 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 TOWCTRANS 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm towctrans +.Nd convert a wide character with a specified map +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.In wctype.h +.Ft wint_t +.Fn towctrans "wint_t wc" "wctrans_t charmap" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn towctrans +function converts a wide character +.Fa wc +with a character mapping +.Fa charmap . +.Pp +The behaviour of +.Fn towctrans +is undefined if the +.Fn towctrans +function is called with an invalid +.Fa charmap +(changes of +.Dv LC_CTYPE +category invalidate +.Fa charmap ) +or invalid wide character +.Fa wc . +.Pp +The behaviour of +.Fn towctrans +is affected by the +.Dv LC_CTYPE +category of the current locale. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn towctrans +returns the resulting character of the conversion. +.\" ---------------------------------------------------------------------- +.Sh ERRORS +No errors are defined. +.\" ---------------------------------------------------------------------- +.Sh SEE ALSO +.Xr iswctype 3 , +.Xr setlocale 3 , +.Xr wctrans 3 , +.Xr wctype 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn towctrans +function conforms to +.St -isoC-amd1 . diff --git a/lib/libc/locale/wcstod.c b/lib/libc/locale/wcstod.c new file mode 100644 index 00000000000..c9879314a1a --- /dev/null +++ b/lib/libc/locale/wcstod.c @@ -0,0 +1,126 @@ +/* $OpenBSD: wcstod.c,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: wcstod.c,v 1.4 2001/10/28 12:08:43 yamt Exp $ */ + +/*- + * Copyright (c)1999, 2000, 2001 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. + * + * $Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstod.c,v 1.2 2001/09/27 16:23:57 yamt Exp $ + */ + +#include <sys/cdefs.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> +#include <wctype.h> + +double +wcstod(const wchar_t *nptr, wchar_t **endptr) +{ + const wchar_t *src; + size_t size; + const wchar_t *start; + + /* + * check length of string and call strtod + */ + src = nptr; + + /* skip space first */ + while (iswspace(*src)) { + src++; + } + + /* get length of string */ + start = src; + if (wcschr(L"+-", *src)) + src++; + size = wcsspn(src, L"0123456789"); + src += size; + if (*src == L'.') {/* XXX use localeconv */ + src++; + size = wcsspn(src, L"0123456789"); + src += size; + } + if (wcschr(L"Ee", *src)) { + src++; + if (wcschr(L"+-", *src)) + src++; + size = wcsspn(src, L"0123456789"); + src += size; + } + size = src - start; + + /* + * convert to a char-string and pass it to strtod. + * + * since all mb chars used to represent a double-constant + * are in the portable character set, we can assume + * that they are 1-byte chars. + */ + if (size) + { + mbstate_t st; + char *buf; + char *end; + const wchar_t *s; + size_t size_converted; + double result; + + buf = malloc(size + 1); + if (!buf) { + /* error */ + errno = ENOMEM; /* XXX */ + return 0; + } + + s = start; + memset(&st, 0, sizeof(st)); + size_converted = wcsrtombs(buf, &s, size, &st); + if (size != size_converted) { + /* XXX should not happen */ + free(buf); + errno = EILSEQ; + return 0; + } + + buf[size] = 0; + result = strtod(buf, &end); + + free(buf); + + if (endptr) + /* LINTED bad interface */ + *endptr = (wchar_t*)start + (end - buf); + + return result; + } + + if (endptr) + /* LINTED bad interface */ + *endptr = (wchar_t*)start; + + return 0; +} diff --git a/lib/libc/locale/wcstol.c b/lib/libc/locale/wcstol.c new file mode 100644 index 00000000000..b99506e3aa5 --- /dev/null +++ b/lib/libc/locale/wcstol.c @@ -0,0 +1,22 @@ +/* $OpenBSD: wcstol.c,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: wcstol.c,v 1.2 2003/03/11 09:21:23 tshiozak Exp $ */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: wcstol.c,v 1.1 2005/07/01 08:59:27 espie Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> +#include <wchar.h> +#include <wctype.h> + +#include "wctoint.h" + +#define FUNCNAME wcstol +typedef long int_type; +#define MIN_VALUE LONG_MIN +#define MAX_VALUE LONG_MAX + +#include "_wcstol.h" diff --git a/lib/libc/locale/wcstoll.c b/lib/libc/locale/wcstoll.c new file mode 100644 index 00000000000..1ccafa489f3 --- /dev/null +++ b/lib/libc/locale/wcstoll.c @@ -0,0 +1,22 @@ +/* $OpenBSD: wcstoll.c,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: wcstoll.c,v 1.1 2003/03/11 09:21:23 tshiozak Exp $ */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: wcstoll.c,v 1.1 2005/07/01 08:59:27 espie Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> +#include <wchar.h> +#include <wctype.h> + +#include "wctoint.h" + +#define FUNCNAME wcstoll +typedef long long int int_type; +#define MIN_VALUE LLONG_MIN +#define MAX_VALUE LLONG_MAX + +#include "_wcstol.h" diff --git a/lib/libc/locale/wcstoul.c b/lib/libc/locale/wcstoul.c new file mode 100644 index 00000000000..6526a3615c6 --- /dev/null +++ b/lib/libc/locale/wcstoul.c @@ -0,0 +1,21 @@ +/* $OpenBSD: wcstoul.c,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: wcstoul.c,v 1.2 2003/03/11 09:21:24 tshiozak Exp $ */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: wcstoul.c,v 1.1 2005/07/01 08:59:27 espie Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> +#include <wchar.h> +#include <wctype.h> + +#include "wctoint.h" + +#define FUNCNAME wcstoul +typedef unsigned long uint_type; +#define MAX_VALUE ULONG_MAX + +#include "_wcstoul.h" diff --git a/lib/libc/locale/wcstoull.c b/lib/libc/locale/wcstoull.c new file mode 100644 index 00000000000..2d4bfbcf3df --- /dev/null +++ b/lib/libc/locale/wcstoull.c @@ -0,0 +1,21 @@ +/* $OpenBSD: wcstoull.c,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: wcstoull.c,v 1.1 2003/03/11 09:21:24 tshiozak Exp $ */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: wcstoull.c,v 1.1 2005/07/01 08:59:27 espie Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdlib.h> +#include <wchar.h> +#include <wctype.h> + +#include "wctoint.h" + +#define FUNCNAME wcstoull +typedef unsigned long long int uint_type; +#define MAX_VALUE ULLONG_MAX + +#include "_wcstoul.h" diff --git a/lib/libc/locale/wctoint.h b/lib/libc/locale/wctoint.h new file mode 100644 index 00000000000..c9bf084c348 --- /dev/null +++ b/lib/libc/locale/wctoint.h @@ -0,0 +1,79 @@ +/* $OpenBSD: wctoint.h,v 1.1 2005/07/01 08:59:27 espie Exp $ */ +/* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */ + +/*- + * Copyright (c)2001 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. + * + * $Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $ + */ + + +__inline static int +wctoint(wchar_t wc) +{ + int n; + + switch (wc) { + case L'0': n = 0; break; + case L'1': n = 1; break; + case L'2': n = 2; break; + case L'3': n = 3; break; + case L'4': n = 4; break; + case L'5': n = 5; break; + case L'6': n = 6; break; + case L'7': n = 7; break; + case L'8': n = 8; break; + case L'9': n = 9; break; + case L'A': case L'a': n = 10; break; + case L'B': case L'b': n = 11; break; + case L'C': case L'c': n = 12; break; + case L'D': case L'd': n = 13; break; + case L'E': case L'e': n = 14; break; + case L'F': case L'f': n = 15; break; + case L'G': case L'g': n = 16; break; + case L'H': case L'h': n = 17; break; + case L'I': case L'i': n = 18; break; + case L'J': case L'j': n = 19; break; + case L'K': case L'k': n = 20; break; + case L'L': case L'l': n = 21; break; + case L'M': case L'm': n = 22; break; + case L'N': case L'n': n = 23; break; + case L'O': case L'o': n = 24; break; + case L'P': case L'p': n = 25; break; + case L'Q': case L'q': n = 26; break; + case L'R': case L'r': n = 27; break; + case L'S': case L's': n = 28; break; + case L'T': case L't': n = 29; break; + case L'U': case L'u': n = 30; break; + case L'V': case L'v': n = 31; break; + case L'W': case L'w': n = 32; break; + case L'X': case L'x': n = 33; break; + case L'Y': case L'y': n = 34; break; + case L'Z': case L'z': n = 35; break; + default: n = -1; break; /* error */ + } + + return n; +} diff --git a/lib/libc/locale/wctrans.3 b/lib/libc/locale/wctrans.3 new file mode 100644 index 00000000000..8a09a63ba2f --- /dev/null +++ b/lib/libc/locale/wctrans.3 @@ -0,0 +1,88 @@ +.\" $OpenBSD: wctrans.3,v 1.1 2005/07/01 08:59:27 espie Exp $ +.\" +.\" $NetBSD: wctrans.3,v 1.4 2004/01/24 16:58:54 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 WCTRANS 3 +.Os +.\" ---------------------------------------------------------------------- +.Sh NAME +.Nm wctrans +.Nd get character mapping identifier by name +.\" ---------------------------------------------------------------------- +.Sh SYNOPSIS +.In wctype.h +.Ft wctrans_t +.Fn wctrans "const char *charmap" +.\" ---------------------------------------------------------------------- +.Sh DESCRIPTION +The +.Fn wctrans +function returns a character mapping identifier corresponding to the +locale-specific character mapping name +.Fa charmap . +This identifier can be used on the subsequent calls of +.Fn towctrans . +The following names are defined in all locales: +.Bd -literal -offset indent +tolower toupper +.Ed +.Pp +The behaviour of +.Fn wctrans +is affected by the +.Dv LC_CTYPE +category of the current locale. +.\" ---------------------------------------------------------------------- +.Sh RETURN VALUES +.Fn wctrans +returns: +.Bl -tag -width 012345678901 +.It 0 +If the string +.Fa charmap +does not corresponding to a valid character mapping name. +.It non-zero +A character mapping identifier corresponding to +.Fa charmap . +.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 wctype 3 +.\" ---------------------------------------------------------------------- +.Sh STANDARDS +The +.Fn towctrans +function conforms to +.St -isoC-amd1 . diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index de1b423353c..956f9e938e4 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ major=38 -minor=0 +minor=1 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then libpthread must also be updated. |