diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-09-05 09:47:04 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-09-05 09:47:04 +0000 |
commit | b39bc242141259d39f8fd57ba90d778f9c734fff (patch) | |
tree | 6b52c4a753e3901643cce5ce6e19cd54399aad92 /lib/libc | |
parent | 8fb4b2b54d8a29c61c6df479a1351f098879bbc2 (diff) |
Delete some abstraction that we don't and won't need.
Declare functions rather than generating declarations with macros.
Just call functions rather than mainting function pointer tables.
Purge unused arguments. Simplify mbstate_t casting.
Garbage collect one empty and one unused function.
As a bonus, make mbsinit(3) work at all, it returned garbage
in the past due to a missing cast when passing mbstate_t.
Apart from that, no functional change.
No libc bump needed; only private functions are removed and
change prototype and only private structs change size.
OK stsp@ mpi@; deraadt@ likes the general direction.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/citrus/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_ctype.c | 61 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_ctype.h | 25 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_ctype_local.h | 87 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_none.c | 38 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_none.h | 39 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_utf8.c | 35 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_utf8.h | 41 | ||||
-rw-r--r-- | lib/libc/locale/multibyte.h | 50 | ||||
-rw-r--r-- | lib/libc/locale/multibyte_citrus.c | 44 | ||||
-rw-r--r-- | lib/libc/locale/rune.c | 15 | ||||
-rw-r--r-- | lib/libc/locale/rune_local.h | 3 | ||||
-rw-r--r-- | lib/libc/locale/runetable.c | 2 | ||||
-rw-r--r-- | lib/libc/locale/runetype.h | 3 | ||||
-rw-r--r-- | lib/libc/locale/setrunelocale.c | 25 |
15 files changed, 67 insertions, 405 deletions
diff --git a/lib/libc/citrus/Makefile.inc b/lib/libc/citrus/Makefile.inc index b1466442dd9..de833401d8a 100644 --- a/lib/libc/citrus/Makefile.inc +++ b/lib/libc/citrus/Makefile.inc @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.1 2010/07/27 16:59:03 stsp Exp $ +# $OpenBSD: Makefile.inc,v 1.2 2016/09/05 09:47:02 schwarze Exp $ # citrus sources .PATH: ${LIBCSRCDIR}/citrus -SRCS+= citrus_ctype.c citrus_none.c citrus_utf8.c +SRCS+= citrus_none.c citrus_utf8.c CFLAGS+=-I${.CURDIR} diff --git a/lib/libc/citrus/citrus_ctype.c b/lib/libc/citrus/citrus_ctype.c deleted file mode 100644 index 125428210ca..00000000000 --- a/lib/libc/citrus/citrus_ctype.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $OpenBSD: citrus_ctype.c,v 1.5 2015/08/27 04:37:09 guenther Exp $ */ -/* $NetBSD: citrus_ctype.c,v 1.5 2008/06/14 16:01:07 tnozaki Exp $ */ - -/*- - * Copyright (c)1999, 2000, 2001, 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. - */ - -#include <sys/types.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <wchar.h> -#include "citrus_ctype.h" -#include "citrus_none.h" -#include "citrus_utf8.h" - -struct _citrus_ctype_rec _citrus_ctype_none = { - &_citrus_none_ctype_ops, /* cc_ops */ - 1 /* cc_mb_cur_max */ -}; - -static struct _citrus_ctype_rec _citrus_ctype_utf8 = { - &_citrus_utf8_ctype_ops, /* cc_ops */ - _CITRUS_UTF8_MB_CUR_MAX /* cc_mb_cur_max */ -}; - -int -_citrus_ctype_open(struct _citrus_ctype_rec **rcc, char const *encname) -{ - if (!strcmp(encname, "NONE")) { - *rcc = &_citrus_ctype_none; - return (0); - } else if (!strcmp(encname, "UTF8")) { - *rcc = &_citrus_ctype_utf8; - return (0); - } - - return (-1); -} diff --git a/lib/libc/citrus/citrus_ctype.h b/lib/libc/citrus/citrus_ctype.h index 5949111216a..6c18b8d2dac 100644 --- a/lib/libc/citrus/citrus_ctype.h +++ b/lib/libc/citrus/citrus_ctype.h @@ -1,5 +1,4 @@ -/* $OpenBSD: citrus_ctype.h,v 1.4 2015/08/27 04:37:09 guenther Exp $ */ -/* $NetBSD: citrus_ctype.h,v 1.2 2003/03/05 20:18:15 tshiozak Exp $ */ +/* $OpenBSD: citrus_ctype.h,v 1.5 2016/09/05 09:47:02 schwarze Exp $ */ /*- * Copyright (c)2002 Citrus Project, @@ -31,12 +30,28 @@ #ifndef _CITRUS_CTYPE_H_ #define _CITRUS_CTYPE_H_ -#include "citrus_ctype_local.h" +#define _CITRUS_UTF8_MB_CUR_MAX 4 __BEGIN_HIDDEN_DECLS -extern struct _citrus_ctype_rec _citrus_ctype_none; +size_t _citrus_none_ctype_mbrtowc(wchar_t * __restrict, + const char * __restrict, size_t); +size_t _citrus_none_ctype_mbsnrtowcs(wchar_t * __restrict, + const char ** __restrict, size_t, size_t); +size_t _citrus_none_ctype_wcrtomb(char * __restrict, wchar_t); +size_t _citrus_none_ctype_wcsnrtombs(char * __restrict, + const wchar_t ** __restrict, size_t, size_t); -int _citrus_ctype_open(struct _citrus_ctype_rec **, char const *); +size_t _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict, + const char * __restrict, size_t, mbstate_t * __restrict); +int _citrus_utf8_ctype_mbsinit(const mbstate_t * __restrict); +size_t _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict, + const char ** __restrict, size_t, size_t, + mbstate_t * __restrict); +size_t _citrus_utf8_ctype_wcrtomb(char * __restrict, wchar_t, + mbstate_t * __restrict); +size_t _citrus_utf8_ctype_wcsnrtombs(char * __restrict, + const wchar_t ** __restrict, size_t, size_t, + mbstate_t * __restrict); __END_HIDDEN_DECLS #endif diff --git a/lib/libc/citrus/citrus_ctype_local.h b/lib/libc/citrus/citrus_ctype_local.h deleted file mode 100644 index 7753ac1513a..00000000000 --- a/lib/libc/citrus/citrus_ctype_local.h +++ /dev/null @@ -1,87 +0,0 @@ -/* $OpenBSD: citrus_ctype_local.h,v 1.4 2013/05/03 13:53:49 stsp Exp $ */ -/* $NetBSD: citrus_ctype_local.h,v 1.2 2003/03/05 20:18:15 tshiozak 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. - * - */ - -#ifndef _CITRUS_CTYPE_LOCAL_H_ -#define _CITRUS_CTYPE_LOCAL_H_ - -#define _CITRUS_CTYPE_DECLS(_e_) \ -size_t _citrus_##_e_##_ctype_mbrtowc(wchar_t * __restrict, \ - const char * __restrict, size_t, \ - void * __restrict); \ -int _citrus_##_e_##_ctype_mbsinit(const void * __restrict); \ -size_t _citrus_##_e_##_ctype_mbsnrtowcs(wchar_t * __restrict, \ - const char ** __restrict, \ - size_t, size_t, \ - void * __restrict); \ -size_t _citrus_##_e_##_ctype_wcrtomb(char * __restrict, wchar_t, \ - void * __restrict); \ -size_t _citrus_##_e_##_ctype_wcsnrtombs(char * __restrict, \ - const wchar_t ** __restrict, \ - size_t, size_t, \ - void * __restrict); \ - -#define _CITRUS_CTYPE_DEF_OPS(_e_) \ -struct _citrus_ctype_ops_rec _citrus_##_e_##_ctype_ops = { \ - /* co_mbrtowc */ &_citrus_##_e_##_ctype_mbrtowc, \ - /* co_mbsinit */ &_citrus_##_e_##_ctype_mbsinit, \ - /* co_mbsnrtowcs */ &_citrus_##_e_##_ctype_mbsnrtowcs, \ - /* co_wcrtomb */ &_citrus_##_e_##_ctype_wcrtomb, \ - /* co_wcsnrtombs */ &_citrus_##_e_##_ctype_wcsnrtombs, \ -} - -typedef size_t (*_citrus_ctype_mbrtowc_t) - (wchar_t * __restrict, const char * __restrict, - size_t, void * __restrict); -typedef int (*_citrus_ctype_mbsinit_t) (const void * __restrict); -typedef size_t (*_citrus_ctype_mbsnrtowcs_t) - (wchar_t * __restrict, const char ** __restrict, - size_t, size_t, void * __restrict); -typedef size_t (*_citrus_ctype_wcrtomb_t) - (char * __restrict, wchar_t, void * __restrict); -typedef size_t (*_citrus_ctype_wcsnrtombs_t) - (char * __restrict, const wchar_t ** __restrict, - size_t, size_t, void * __restrict); - -struct _citrus_ctype_ops_rec { - _citrus_ctype_mbrtowc_t co_mbrtowc; - _citrus_ctype_mbsinit_t co_mbsinit; - _citrus_ctype_mbsnrtowcs_t co_mbsnrtowcs; - _citrus_ctype_wcrtomb_t co_wcrtomb; - _citrus_ctype_wcsnrtombs_t co_wcsnrtombs; -}; - -#define _CITRUS_DEFAULT_CTYPE_NAME "NONE" - -struct _citrus_ctype_rec { - struct _citrus_ctype_ops_rec *cc_ops; - size_t cc_mb_cur_max; -}; - -#endif diff --git a/lib/libc/citrus/citrus_none.c b/lib/libc/citrus/citrus_none.c index b09a567ae04..98c0abeda8d 100644 --- a/lib/libc/citrus/citrus_none.c +++ b/lib/libc/citrus/citrus_none.c @@ -1,4 +1,4 @@ -/* $OpenBSD: citrus_none.c,v 1.6 2015/11/01 03:45:28 guenther Exp $ */ +/* $OpenBSD: citrus_none.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: citrus_none.c,v 1.18 2008/06/14 16:01:07 tnozaki Exp $ */ /*- @@ -38,9 +38,6 @@ #include <wchar.h> #include "citrus_ctype.h" -#include "citrus_none.h" - -_CITRUS_CTYPE_DEF_OPS(none); /* * Convert an unsigned char value into a char value without relying on @@ -57,13 +54,8 @@ wrapv(unsigned char ch) size_t _citrus_none_ctype_mbrtowc(wchar_t * __restrict pwc, - const char * __restrict s, size_t n, - void * __restrict pspriv) + const char * __restrict s, size_t n) { - /* pwc may be NULL */ - /* s may be NULL */ - /* pspriv appears to be unused */ - if (s == NULL) return 0; if (n == 0) @@ -73,23 +65,12 @@ _citrus_none_ctype_mbrtowc(wchar_t * __restrict pwc, return (*s != '\0'); } -int -_citrus_none_ctype_mbsinit(const void * __restrict pspriv) -{ - return (1); /* always initial state */ -} - size_t _citrus_none_ctype_mbsnrtowcs(wchar_t * __restrict dst, - const char ** __restrict src, - size_t nmc, size_t len, - void * __restrict pspriv) + const char ** __restrict src, size_t nmc, size_t len) { size_t i; - /* dst may be NULL */ - /* pspriv appears to be unused */ - if (dst == NULL) return strnlen(*src, nmc); @@ -104,12 +85,8 @@ _citrus_none_ctype_mbsnrtowcs(wchar_t * __restrict dst, } size_t -_citrus_none_ctype_wcrtomb(char * __restrict s, - wchar_t wc, void * __restrict pspriv) +_citrus_none_ctype_wcrtomb(char * __restrict s, wchar_t wc) { - /* s may be NULL */ - /* ps appears to be unused */ - if (s == NULL) return (1); @@ -124,15 +101,10 @@ _citrus_none_ctype_wcrtomb(char * __restrict s, size_t _citrus_none_ctype_wcsnrtombs(char * __restrict dst, - const wchar_t ** __restrict src, - size_t nwc, size_t len, - void * __restrict pspriv) + const wchar_t ** __restrict src, size_t nwc, size_t len) { size_t i; - /* dst may be NULL */ - /* pspriv appears to be unused */ - if (dst == NULL) { for (i = 0; i < nwc; i++) { wchar_t wc = (*src)[i]; diff --git a/lib/libc/citrus/citrus_none.h b/lib/libc/citrus/citrus_none.h deleted file mode 100644 index 6f74784b5a5..00000000000 --- a/lib/libc/citrus/citrus_none.h +++ /dev/null @@ -1,39 +0,0 @@ -/* $OpenBSD: citrus_none.h,v 1.2 2015/08/27 04:37:09 guenther Exp $ */ -/* $NetBSD: citrus_none.h,v 1.3 2003/06/25 09:51:38 tshiozak 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. - */ - -#ifndef _CITRUS_NONE_H_ -#define _CITRUS_NONE_H_ - -__BEGIN_HIDDEN_DECLS -extern struct _citrus_ctype_ops_rec _citrus_none_ctype_ops; - -_CITRUS_CTYPE_DECLS(none); -__END_HIDDEN_DECLS - -#endif diff --git a/lib/libc/citrus/citrus_utf8.c b/lib/libc/citrus/citrus_utf8.c index 70ae39927b6..016e5d5428e 100644 --- a/lib/libc/citrus/citrus_utf8.c +++ b/lib/libc/citrus/citrus_utf8.c @@ -1,4 +1,4 @@ -/* $OpenBSD: citrus_utf8.c,v 1.15 2015/11/01 03:45:28 guenther Exp $ */ +/* $OpenBSD: citrus_utf8.c,v 1.16 2016/09/05 09:47:03 schwarze Exp $ */ /*- * Copyright (c) 2002-2004 Tim J. Robbins @@ -38,12 +38,9 @@ #include <wchar.h> #include "citrus_ctype.h" -#include "citrus_utf8.h" #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) -_CITRUS_CTYPE_DEF_OPS(utf8); - struct _utf8_state { wchar_t ch; int want; @@ -52,14 +49,13 @@ struct _utf8_state { size_t _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc, - const char * __restrict s, size_t n, - void * __restrict pspriv) + const char * __restrict s, size_t n, mbstate_t * __restrict ps) { struct _utf8_state *us; int ch, i, mask, want; wchar_t lbound, wch; - us = (struct _utf8_state *)pspriv; + us = (struct _utf8_state *)ps; if (us->want < 0 || us->want > _CITRUS_UTF8_MB_CUR_MAX) { errno = EINVAL; @@ -182,22 +178,20 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc, } int -_citrus_utf8_ctype_mbsinit(const void * __restrict pspriv) +_citrus_utf8_ctype_mbsinit(const mbstate_t * __restrict ps) { - return (pspriv == NULL || - ((const struct _utf8_state *)pspriv)->want == 0); + return (((const struct _utf8_state *)ps)->want == 0); } size_t _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict dst, - const char ** __restrict src, - size_t nmc, size_t len, - void * __restrict pspriv) + const char ** __restrict src, size_t nmc, size_t len, + mbstate_t * __restrict ps) { struct _utf8_state *us; size_t i, o, r; - us = (struct _utf8_state *)pspriv; + us = (struct _utf8_state *)ps; if (dst == NULL) { /* @@ -269,14 +263,14 @@ _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict dst, } size_t -_citrus_utf8_ctype_wcrtomb(char * __restrict s, - wchar_t wc, void * __restrict pspriv) +_citrus_utf8_ctype_wcrtomb(char * __restrict s, wchar_t wc, + mbstate_t * __restrict ps) { struct _utf8_state *us; unsigned char lead; int i, len; - us = (struct _utf8_state *)pspriv; + us = (struct _utf8_state *)ps; if (us->want != 0) { errno = EINVAL; @@ -331,15 +325,14 @@ _citrus_utf8_ctype_wcrtomb(char * __restrict s, size_t _citrus_utf8_ctype_wcsnrtombs(char * __restrict dst, - const wchar_t ** __restrict src, - size_t nwc, size_t len, - void * __restrict pspriv) + const wchar_t ** __restrict src, size_t nwc, size_t len, + mbstate_t * __restrict ps) { struct _utf8_state *us; char buf[_CITRUS_UTF8_MB_CUR_MAX]; size_t i, o, r; - us = (struct _utf8_state *)pspriv; + us = (struct _utf8_state *)ps; if (us->want != 0) { errno = EINVAL; diff --git a/lib/libc/citrus/citrus_utf8.h b/lib/libc/citrus/citrus_utf8.h deleted file mode 100644 index ee6634c76b6..00000000000 --- a/lib/libc/citrus/citrus_utf8.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: citrus_utf8.h,v 1.3 2015/08/27 04:37:09 guenther Exp $ */ -/* $NetBSD: citrus_utf8.h,v 1.2 2003/06/25 09:51:49 tshiozak 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. - */ - -#ifndef _CITRUS_UTF8_H_ -#define _CITRUS_UTF8_H_ - -__BEGIN_HIDDEN_DECLS -extern struct _citrus_ctype_ops_rec _citrus_utf8_ctype_ops; - -#define _CITRUS_UTF8_MB_CUR_MAX 4 - -_CITRUS_CTYPE_DECLS(utf8); -__END_HIDDEN_DECLS - -#endif diff --git a/lib/libc/locale/multibyte.h b/lib/libc/locale/multibyte.h deleted file mode 100644 index 9a69ada2751..00000000000 --- a/lib/libc/locale/multibyte.h +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: multibyte.h,v 1.1 2010/07/27 16:59:04 stsp Exp $ */ -/* $NetBSD: multibyte.h,v 1.5 2009/01/11 02:46:28 christos 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. - */ - -#ifndef _MULTIBYTE_H_ -#define _MULTIBYTE_H_ - -typedef struct _RuneStatePriv { - _RuneLocale *__runelocale; - char __private __attribute__((__aligned__)); -} _RuneStatePriv; - -typedef union _RuneState { - mbstate_t __pad; - struct _RuneStatePriv __priv; -#define rs_runelocale __priv.__runelocale -#define rs_private __priv.__private -} _RuneState; -#define _RUNE_STATE_PRIVSIZE (sizeof(mbstate_t)-offsetof(_RuneStatePriv, __private)) - -#define _ps_to_runestate(ps) ((_RuneState *)(void *)(ps)) -#define _ps_to_runelocale(ps) (_ps_to_runestate(ps)->rs_runelocale) -#define _ps_to_private(ps) ((void *)&_ps_to_runestate(ps)->rs_private) - -#endif /*_MULTIBYTE_H_*/ diff --git a/lib/libc/locale/multibyte_citrus.c b/lib/libc/locale/multibyte_citrus.c index 5e30f5bbee9..c4566579621 100644 --- a/lib/libc/locale/multibyte_citrus.c +++ b/lib/libc/locale/multibyte_citrus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: multibyte_citrus.c,v 1.6 2015/09/12 16:23:14 guenther Exp $ */ +/* $OpenBSD: multibyte_citrus.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: multibyte_amd1.c,v 1.7 2009/01/11 02:46:28 christos Exp $ */ /*- @@ -28,28 +28,18 @@ */ #include <sys/types.h> -#include <errno.h> #include <stdint.h> +#include <stdlib.h> #include <wchar.h> #include "citrus_ctype.h" -#include "rune.h" -#include "multibyte.h" int mbsinit(const mbstate_t *ps) { - struct _citrus_ctype_rec *cc; - _RuneLocale *rl; - - if (ps == NULL) + if (ps == NULL || __mb_cur_max == 1) return 1; - - rl = _ps_to_runelocale(ps); - if (rl == NULL) - rl = _CurrentRuneLocale; - cc = rl->rl_citrus_ctype; - return (*cc->cc_ops->co_mbsinit)(ps); + return _citrus_utf8_ctype_mbsinit(ps); } DEF_STRONG(mbsinit); @@ -57,12 +47,12 @@ size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_mbrtowc)(pwc, s, n, _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_mbrtowc(pwc, s, n); + return _citrus_utf8_ctype_mbrtowc(pwc, s, n, ps); } DEF_STRONG(mbrtowc); @@ -82,13 +72,12 @@ mbsnrtowcs(wchar_t *dst, const char **src, size_t nmc, size_t len, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_mbsnrtowcs)(dst, src, nmc, len, - _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_mbsnrtowcs(dst, src, nmc, len); + return _citrus_utf8_ctype_mbsnrtowcs(dst, src, nmc, len, ps); } DEF_WEAK(mbsnrtowcs); @@ -96,12 +85,12 @@ size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_wcrtomb)(s, wc, _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_wcrtomb(s, wc); + return _citrus_utf8_ctype_wcrtomb(s, wc, ps); } DEF_STRONG(wcrtomb); @@ -121,12 +110,11 @@ wcsnrtombs(char *dst, const wchar_t **src, size_t nwc, size_t len, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_wcsnrtombs)(dst, src, nwc, len, - _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_wcsnrtombs(dst, src, nwc, len); + return _citrus_utf8_ctype_wcsnrtombs(dst, src, nwc, len, ps); } DEF_WEAK(wcsnrtombs); diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 7774859df86..d5c3e5c0681 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rune.c,v 1.6 2016/02/05 04:10:48 jsg Exp $ */ +/* $OpenBSD: rune.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: rune.c,v 1.26 2004/05/09 11:26:33 kleink Exp $ */ /*- @@ -319,16 +319,3 @@ err: free(hostdata); return NULL; } - -void -_NukeRune(_RuneLocale *rl) -{ - - if (rl != &_DefaultRuneLocale) { - _freeentry(&rl->rl_runetype_ext); - free(rl->rl_tabs); - free(rl->rl_codeset); - free(rl); - } -} - diff --git a/lib/libc/locale/rune_local.h b/lib/libc/locale/rune_local.h index 97491447955..7f2d5d90a5b 100644 --- a/lib/libc/locale/rune_local.h +++ b/lib/libc/locale/rune_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rune_local.h,v 1.4 2015/09/13 11:38:08 guenther Exp $ */ +/* $OpenBSD: rune_local.h,v 1.5 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: rune_local.h,v 1.7 2003/03/02 22:18:15 tshiozak Exp $ */ /*- @@ -34,7 +34,6 @@ __BEGIN_HIDDEN_DECLS /* rune.c */ extern _RuneLocale *_Read_RuneMagi(FILE *fp); -extern void _NukeRune(_RuneLocale *); /* setrunelocale.c */ extern int _xpg4_setrunelocale(const char *); diff --git a/lib/libc/locale/runetable.c b/lib/libc/locale/runetable.c index 9f0bd4afc0b..ad4e22c9631 100644 --- a/lib/libc/locale/runetable.c +++ b/lib/libc/locale/runetable.c @@ -42,7 +42,6 @@ #include "rune.h" #include "rune_local.h" #include "citrus_ctype.h" -#include "citrus_none.h" _RuneLocale _DefaultRuneLocale = { _RUNE_MAGIC_1, @@ -249,7 +248,6 @@ _RuneLocale _DefaultRuneLocale = { { 0, NULL }, NULL, 0, "US-ASCII", - &_citrus_ctype_none, { { NULL, NULL, NULL }, { NULL, NULL, NULL }, diff --git a/lib/libc/locale/runetype.h b/lib/libc/locale/runetype.h index c39ec6dce65..e12ed1f0818 100644 --- a/lib/libc/locale/runetype.h +++ b/lib/libc/locale/runetype.h @@ -1,7 +1,7 @@ #ifndef _NB_RUNETYPE_H_ #define _NB_RUNETYPE_H_ -/* $OpenBSD: runetype.h,v 1.7 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: runetype.h,v 1.8 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: runetype.h,v 1.18 2003/08/07 16:43:04 agc Exp $ */ /*- * Copyright (c) 1993 @@ -199,7 +199,6 @@ typedef struct { * the following portion is generated on the fly */ char *rl_codeset; - struct _citrus_ctype_rec *rl_citrus_ctype; _WCTransEntry rl_wctrans[_WCTRANS_NINDEXES]; _WCTypeEntry rl_wctype[_WCTYPE_NINDEXES]; diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index 2ade6c4a84f..754a1b30dfe 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/setrunelocale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setrunelocale.c,v 1.14 2016/09/02 15:00:14 schwarze Exp $ */ +/* $OpenBSD: setrunelocale.c,v 1.15 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: setrunelocale.c,v 1.14 2003/08/07 16:43:07 agc Exp $ */ /*- @@ -107,7 +107,6 @@ int _newrunelocale(const char *path) { FILE *fp; - _RuneLocale *rl; if (_Utf8RuneLocale != NULL) return 0; @@ -115,20 +114,11 @@ _newrunelocale(const char *path) if ((fp = fopen(path, "re")) == NULL) return ENOENT; - if ((rl = _Read_RuneMagi(fp)) == NULL) { + if ((_Utf8RuneLocale = _Read_RuneMagi(fp)) == NULL) { fclose(fp); return EFTYPE; } fclose(fp); - - rl->rl_citrus_ctype = NULL; - - if (_citrus_ctype_open(&rl->rl_citrus_ctype, rl->rl_encoding)) { - _NukeRune(rl); - return EINVAL; - } - _Utf8RuneLocale = rl; - return 0; } @@ -141,7 +131,8 @@ _xpg4_setrunelocale(const char *locname) if (!strcmp(locname, "C") || !strcmp(locname, "POSIX")) { _CurrentRuneLocale = &_DefaultRuneLocale; - goto found; + __mb_cur_max = 1; + return 0; } /* Assumes "language[_territory][.codeset]" locale name. */ @@ -149,7 +140,8 @@ _xpg4_setrunelocale(const char *locname) if (dot == NULL) { /* No encoding specified. Fall back to ASCII. */ _CurrentRuneLocale = &_DefaultRuneLocale; - goto found; + __mb_cur_max = 1; + return 0; } encoding = dot + 1; @@ -167,9 +159,6 @@ _xpg4_setrunelocale(const char *locname) if (_Utf8RuneLocale == NULL) return ENOENT; _CurrentRuneLocale = _Utf8RuneLocale; - -found: - __mb_cur_max = _CurrentRuneLocale->rl_citrus_ctype->cc_mb_cur_max; - + __mb_cur_max = _CITRUS_UTF8_MB_CUR_MAX; return 0; } |