]> git.ipfire.org Git - thirdparty/glibc.git/blob - iconvdata/8bit-generic.c
Update.
[thirdparty/glibc.git] / iconvdata / 8bit-generic.c
1 /* Generic conversion to and from 8bit charsets.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #define FROM_LOOP from_generic
22 #define TO_LOOP to_generic
23 #define DEFINE_INIT 1
24 #define DEFINE_FINI 1
25 #define MIN_NEEDED_FROM 1
26 #define MIN_NEEDED_TO 4
27
28
29 /* First define the conversion function from the 8bit charset to UCS4. */
30 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
31 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
32 #define LOOPFCT FROM_LOOP
33 #define BODY \
34 { \
35 uint32_t ch = to_ucs4[*inptr]; \
36 \
37 if (HAS_HOLES && __builtin_expect (ch, L'\1') == L'\0' && *inptr != '\0') \
38 { \
39 /* This is an illegal character. */ \
40 if (! ignore_errors_p ()) \
41 { \
42 result = __GCONV_ILLEGAL_INPUT; \
43 break; \
44 } \
45 \
46 ++*converted; \
47 } \
48 \
49 put32 (outptr, ch); \
50 outptr += 4; \
51 ++inptr; \
52 }
53 #include <iconv/loop.c>
54
55
56 /* Next, define the other direction. */
57 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
58 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
59 #define LOOPFCT TO_LOOP
60 #define BODY \
61 { \
62 uint32_t ch = get32 (inptr); \
63 \
64 if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
65 || (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0)) \
66 { \
67 /* This is an illegal character. */ \
68 if (! ignore_errors_p ()) \
69 { \
70 result = __GCONV_ILLEGAL_INPUT; \
71 break; \
72 } \
73 \
74 ++*converted; \
75 } \
76 else \
77 *outptr++ = from_ucs4[ch]; \
78 \
79 inptr += 4; \
80 }
81 #include <iconv/loop.c>
82
83
84 /* Now define the toplevel functions. */
85 #include <iconv/skeleton.c>