multibyte_c90.c revision 1.2.2.3 1 1.2.2.3 nathanw /* $NetBSD: multibyte_c90.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_c90.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 <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 mbstowcs(wchar_t *pwcs, const char *s, size_t n)
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 err0 = _citrus_ctype_mbstowcs(_to_cur_ctype(), pwcs, s, n, &ret);
63 1.2.2.2 nathanw if (err0)
64 1.2.2.2 nathanw errno = err0;
65 1.2.2.2 nathanw
66 1.2.2.2 nathanw return ret;
67 1.2.2.2 nathanw }
68 1.2.2.2 nathanw
69 1.2.2.2 nathanw int
70 1.2.2.2 nathanw mbtowc(wchar_t *pw, const char *s, size_t n)
71 1.2.2.2 nathanw {
72 1.2.2.2 nathanw int ret;
73 1.2.2.2 nathanw int err0;
74 1.2.2.2 nathanw
75 1.2.2.2 nathanw err0 = _citrus_ctype_mbtowc(_to_cur_ctype(), pw, s, n, &ret);
76 1.2.2.2 nathanw if (err0)
77 1.2.2.2 nathanw errno = err0;
78 1.2.2.2 nathanw
79 1.2.2.2 nathanw return ret;
80 1.2.2.2 nathanw }
81 1.2.2.2 nathanw
82 1.2.2.2 nathanw size_t
83 1.2.2.2 nathanw wcstombs(char *s, const wchar_t *wcs, size_t n)
84 1.2.2.2 nathanw {
85 1.2.2.2 nathanw size_t ret;
86 1.2.2.2 nathanw int err0;
87 1.2.2.2 nathanw
88 1.2.2.2 nathanw err0 = _citrus_ctype_wcstombs(_to_cur_ctype(), s, wcs, n, &ret);
89 1.2.2.2 nathanw if (err0)
90 1.2.2.2 nathanw errno = err0;
91 1.2.2.2 nathanw
92 1.2.2.2 nathanw return ret;
93 1.2.2.2 nathanw }
94 1.2.2.2 nathanw
95 1.2.2.2 nathanw int
96 1.2.2.2 nathanw wctomb(char *s, wchar_t wc)
97 1.2.2.2 nathanw {
98 1.2.2.2 nathanw int ret;
99 1.2.2.2 nathanw int err0;
100 1.2.2.2 nathanw
101 1.2.2.2 nathanw err0 = _citrus_ctype_wctomb(_to_cur_ctype(), s, wc, &ret);
102 1.2.2.2 nathanw if (err0)
103 1.2.2.2 nathanw errno = err0;
104 1.2.2.2 nathanw
105 1.2.2.2 nathanw return ret;
106 1.2.2.2 nathanw }
107