Home | History | Annotate | Line # | Download | only in locale
multibyte_amd1.c revision 1.2.2.3
      1  1.2.2.3  nathanw /*	$NetBSD: multibyte_amd1.c,v 1.2.2.3 2002/04/25 04:01:43 nathanw Exp $	*/
      2  1.2.2.2  nathanw 
      3  1.2.2.2  nathanw /*-
      4  1.2.2.2  nathanw  * Copyright (c)2002 Citrus Project,
      5  1.2.2.2  nathanw  * All rights reserved.
      6  1.2.2.2  nathanw  *
      7  1.2.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
      8  1.2.2.2  nathanw  * modification, are permitted provided that the following conditions
      9  1.2.2.2  nathanw  * are met:
     10  1.2.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     11  1.2.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     12  1.2.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     15  1.2.2.2  nathanw  *
     16  1.2.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.2.2.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.2.2.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.2.2.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.2.2.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.2.2.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.2.2.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.2.2.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.2.2.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.2.2.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.2.2.2  nathanw  * SUCH DAMAGE.
     27  1.2.2.2  nathanw  */
     28  1.2.2.2  nathanw 
     29  1.2.2.2  nathanw #include <sys/cdefs.h>
     30  1.2.2.2  nathanw #if defined(LIBC_SCCS) && !defined(lint)
     31  1.2.2.3  nathanw __RCSID("$NetBSD: multibyte_amd1.c,v 1.2.2.3 2002/04/25 04:01:43 nathanw Exp $");
     32  1.2.2.2  nathanw #endif /* LIBC_SCCS and not lint */
     33  1.2.2.2  nathanw 
     34  1.2.2.2  nathanw #include <assert.h>
     35  1.2.2.2  nathanw #include <wchar.h>
     36  1.2.2.2  nathanw #include <errno.h>
     37  1.2.2.2  nathanw #include <sys/types.h>
     38  1.2.2.2  nathanw #include <citrus/citrus_module.h>
     39  1.2.2.2  nathanw #include <citrus/citrus_ctype.h>
     40  1.2.2.2  nathanw #include "rune.h"
     41  1.2.2.2  nathanw #include "multibyte.h"
     42  1.2.2.2  nathanw 
     43  1.2.2.2  nathanw size_t
     44  1.2.2.2  nathanw mbrlen(const char *s, size_t n, mbstate_t *ps)
     45  1.2.2.2  nathanw {
     46  1.2.2.2  nathanw 	size_t ret;
     47  1.2.2.2  nathanw 	int err0;
     48  1.2.2.2  nathanw 
     49  1.2.2.2  nathanw 	_fixup_ps(_CurrentRuneLocale, ps, s==NULL);
     50  1.2.2.2  nathanw 
     51  1.2.2.2  nathanw 	err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), s, n,
     52  1.2.2.2  nathanw 				     _ps_to_private(ps), &ret);
     53  1.2.2.2  nathanw 	if (err0)
     54  1.2.2.2  nathanw 		errno = err0;
     55  1.2.2.2  nathanw 
     56  1.2.2.2  nathanw 	return ret;
     57  1.2.2.2  nathanw }
     58  1.2.2.2  nathanw 
     59  1.2.2.2  nathanw int
     60  1.2.2.2  nathanw mbsinit(const mbstate_t *ps)
     61  1.2.2.2  nathanw {
     62  1.2.2.2  nathanw 	int ret;
     63  1.2.2.2  nathanw 	int err0;
     64  1.2.2.2  nathanw 	_RuneLocale *rl;
     65  1.2.2.2  nathanw 
     66  1.2.2.2  nathanw 	if (ps == NULL)
     67  1.2.2.2  nathanw 		return 1;
     68  1.2.2.2  nathanw 
     69  1.2.2.2  nathanw 	if (_ps_to_runelocale(ps) == NULL)
     70  1.2.2.2  nathanw 		rl = _CurrentRuneLocale;
     71  1.2.2.2  nathanw 	else
     72  1.2.2.2  nathanw 		rl = _ps_to_runelocale(ps);
     73  1.2.2.2  nathanw 
     74  1.2.2.2  nathanw 	/* mbsinit should cause no error... */
     75  1.2.2.2  nathanw 	err0 = _citrus_ctype_mbsinit(rl->rl_citrus_ctype,
     76  1.2.2.2  nathanw 				      _ps_to_private_const(ps), &ret);
     77  1.2.2.2  nathanw 	if (err0)
     78  1.2.2.2  nathanw 		errno = err0;
     79  1.2.2.2  nathanw 
     80  1.2.2.2  nathanw 	return ret;
     81  1.2.2.2  nathanw }
     82  1.2.2.2  nathanw 
     83  1.2.2.2  nathanw size_t
     84  1.2.2.3  nathanw mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
     85  1.2.2.3  nathanw {
     86  1.2.2.3  nathanw 	size_t ret;
     87  1.2.2.3  nathanw 	int err0;
     88  1.2.2.3  nathanw 
     89  1.2.2.3  nathanw 	_fixup_ps(_CurrentRuneLocale, ps, s==NULL);
     90  1.2.2.3  nathanw 
     91  1.2.2.3  nathanw 	err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n,
     92  1.2.2.3  nathanw 				      _ps_to_private(ps), &ret);
     93  1.2.2.3  nathanw 	if (err0)
     94  1.2.2.3  nathanw 		errno = err0;
     95  1.2.2.3  nathanw 
     96  1.2.2.3  nathanw 	return ret;
     97  1.2.2.3  nathanw }
     98  1.2.2.3  nathanw 
     99  1.2.2.3  nathanw size_t
    100  1.2.2.2  nathanw mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps)
    101  1.2.2.2  nathanw {
    102  1.2.2.2  nathanw 	size_t ret;
    103  1.2.2.2  nathanw 	int err0;
    104  1.2.2.2  nathanw 
    105  1.2.2.2  nathanw 	_fixup_ps(_CurrentRuneLocale, ps, s==NULL);
    106  1.2.2.2  nathanw 
    107  1.2.2.2  nathanw 	err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), pwcs, s, n,
    108  1.2.2.2  nathanw 					_ps_to_private(ps), &ret);
    109  1.2.2.2  nathanw 	if (err0)
    110  1.2.2.2  nathanw 		errno = err0;
    111  1.2.2.2  nathanw 
    112  1.2.2.2  nathanw 	return ret;
    113  1.2.2.2  nathanw }
    114  1.2.2.2  nathanw 
    115  1.2.2.2  nathanw size_t
    116  1.2.2.2  nathanw wcrtomb(char *s, wchar_t wc, mbstate_t *ps)
    117  1.2.2.2  nathanw {
    118  1.2.2.2  nathanw 	size_t ret;
    119  1.2.2.2  nathanw 	int err0;
    120  1.2.2.2  nathanw 
    121  1.2.2.2  nathanw 	_fixup_ps(_CurrentRuneLocale, ps, s==NULL);
    122  1.2.2.2  nathanw 
    123  1.2.2.3  nathanw 	err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), s, wc,
    124  1.2.2.2  nathanw 				       _ps_to_private(ps), &ret);
    125  1.2.2.2  nathanw 	if (err0)
    126  1.2.2.2  nathanw 		errno = err0;
    127  1.2.2.2  nathanw 
    128  1.2.2.2  nathanw 	return ret;
    129  1.2.2.2  nathanw }
    130  1.2.2.2  nathanw 
    131  1.2.2.2  nathanw size_t
    132  1.2.2.2  nathanw wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps)
    133  1.2.2.2  nathanw {
    134  1.2.2.2  nathanw 	size_t ret;
    135  1.2.2.2  nathanw 	int err0;
    136  1.2.2.2  nathanw 
    137  1.2.2.2  nathanw 	_fixup_ps(_CurrentRuneLocale, ps, s==NULL);
    138  1.2.2.2  nathanw 
    139  1.2.2.2  nathanw 	err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), s, ppwcs, n,
    140  1.2.2.2  nathanw 					_ps_to_private(ps), &ret);
    141  1.2.2.2  nathanw 	if (err0)
    142  1.2.2.2  nathanw 		errno = err0;
    143  1.2.2.2  nathanw 
    144  1.2.2.2  nathanw 	return ret;
    145  1.2.2.2  nathanw }
    146