multibyte_c90.c revision 1.2.2.2 1 1.2.2.2 nathanw /* $NetBSD: multibyte_c90.c,v 1.2.2.2 2002/03/22 20:42:17 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.2 nathanw __RCSID("$NetBSD: multibyte_c90.c,v 1.2.2.2 2002/03/22 20:42:17 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 <stdlib.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 int
44 1.2.2.2 nathanw mblen(const char *s, size_t n)
45 1.2.2.2 nathanw {
46 1.2.2.2 nathanw int ret;
47 1.2.2.2 nathanw int err0;
48 1.2.2.2 nathanw
49 1.2.2.2 nathanw err0 = _citrus_ctype_mblen(_to_cur_ctype(), s, n, &ret);
50 1.2.2.2 nathanw if (err0)
51 1.2.2.2 nathanw errno = err0;
52 1.2.2.2 nathanw
53 1.2.2.2 nathanw return ret;
54 1.2.2.2 nathanw }
55 1.2.2.2 nathanw
56 1.2.2.2 nathanw size_t
57 1.2.2.2 nathanw mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
58 1.2.2.2 nathanw {
59 1.2.2.2 nathanw size_t ret;
60 1.2.2.2 nathanw int err0;
61 1.2.2.2 nathanw
62 1.2.2.2 nathanw _fixup_ps(_CurrentRuneLocale, ps, s==NULL);
63 1.2.2.2 nathanw
64 1.2.2.2 nathanw err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n,
65 1.2.2.2 nathanw _ps_to_private(ps), &ret);
66 1.2.2.2 nathanw if (err0)
67 1.2.2.2 nathanw errno = err0;
68 1.2.2.2 nathanw
69 1.2.2.2 nathanw return ret;
70 1.2.2.2 nathanw }
71 1.2.2.2 nathanw
72 1.2.2.2 nathanw size_t
73 1.2.2.2 nathanw mbstowcs(wchar_t *pwcs, const char *s, size_t n)
74 1.2.2.2 nathanw {
75 1.2.2.2 nathanw size_t ret;
76 1.2.2.2 nathanw int err0;
77 1.2.2.2 nathanw
78 1.2.2.2 nathanw err0 = _citrus_ctype_mbstowcs(_to_cur_ctype(), pwcs, s, n, &ret);
79 1.2.2.2 nathanw if (err0)
80 1.2.2.2 nathanw errno = err0;
81 1.2.2.2 nathanw
82 1.2.2.2 nathanw return ret;
83 1.2.2.2 nathanw }
84 1.2.2.2 nathanw
85 1.2.2.2 nathanw int
86 1.2.2.2 nathanw mbtowc(wchar_t *pw, const char *s, size_t n)
87 1.2.2.2 nathanw {
88 1.2.2.2 nathanw int ret;
89 1.2.2.2 nathanw int err0;
90 1.2.2.2 nathanw
91 1.2.2.2 nathanw err0 = _citrus_ctype_mbtowc(_to_cur_ctype(), pw, s, n, &ret);
92 1.2.2.2 nathanw if (err0)
93 1.2.2.2 nathanw errno = err0;
94 1.2.2.2 nathanw
95 1.2.2.2 nathanw return ret;
96 1.2.2.2 nathanw }
97 1.2.2.2 nathanw
98 1.2.2.2 nathanw size_t
99 1.2.2.2 nathanw wcstombs(char *s, const wchar_t *wcs, size_t n)
100 1.2.2.2 nathanw {
101 1.2.2.2 nathanw size_t ret;
102 1.2.2.2 nathanw int err0;
103 1.2.2.2 nathanw
104 1.2.2.2 nathanw err0 = _citrus_ctype_wcstombs(_to_cur_ctype(), s, wcs, n, &ret);
105 1.2.2.2 nathanw if (err0)
106 1.2.2.2 nathanw errno = err0;
107 1.2.2.2 nathanw
108 1.2.2.2 nathanw return ret;
109 1.2.2.2 nathanw }
110 1.2.2.2 nathanw
111 1.2.2.2 nathanw int
112 1.2.2.2 nathanw wctomb(char *s, wchar_t wc)
113 1.2.2.2 nathanw {
114 1.2.2.2 nathanw int ret;
115 1.2.2.2 nathanw int err0;
116 1.2.2.2 nathanw
117 1.2.2.2 nathanw err0 = _citrus_ctype_wctomb(_to_cur_ctype(), s, wc, &ret);
118 1.2.2.2 nathanw if (err0)
119 1.2.2.2 nathanw errno = err0;
120 1.2.2.2 nathanw
121 1.2.2.2 nathanw return ret;
122 1.2.2.2 nathanw }
123