Update.
[glibc.git] / iconvdata / 8bit-generic.c
blobe0e20e293fde457857ff89df262be66dfc2d629b
1 /* Generic conversion to and from 8bit charsets.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <dlfcn.h>
23 #define FROM_LOOP from_generic
24 #define TO_LOOP to_generic
25 #define DEFINE_INIT 1
26 #define DEFINE_FINI 1
27 #define MIN_NEEDED_FROM 1
28 #define MIN_NEEDED_TO 4
31 /* First define the conversion function from the 8bit charset to UCS4. */
32 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
33 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
34 #define LOOPFCT FROM_LOOP
35 #define BODY \
36 { \
37 uint32_t ch = to_ucs4[*inptr]; \
39 if (HAS_HOLES && __builtin_expect (ch, L'\1') == L'\0' && *inptr != '\0') \
40 { \
41 /* This is an illegal character. */ \
42 if (! ignore_errors_p ()) \
43 { \
44 result = __GCONV_ILLEGAL_INPUT; \
45 break; \
46 } \
48 ++*irreversible; \
49 } \
51 put32 (outptr, ch); \
52 outptr += 4; \
53 ++inptr; \
55 #define LOOP_NEED_FLAGS
56 #include <iconv/loop.c>
59 /* Next, define the other direction. */
60 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
61 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
62 #define LOOPFCT TO_LOOP
63 #define BODY \
64 { \
65 uint32_t ch = get32 (inptr); \
67 if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
68 || (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0)) \
69 { \
70 UNICODE_TAG_HANDLER (ch, 4); \
72 /* This is an illegal character. */ \
73 STANDARD_ERR_HANDLER (4); \
74 } \
76 *outptr++ = from_ucs4[ch]; \
77 inptr += 4; \
79 #define LOOP_NEED_FLAGS
80 #include <iconv/loop.c>
83 /* Now define the toplevel functions. */
84 #include <iconv/skeleton.c>