Update.
[glibc.git] / iconvdata / 8bit-generic.c
blob2ea333199e9936d95a2716bdf3d3598e3eb35492
1 /* Generic conversion to and from 8bit charsets.
2 Copyright (C) 1997, 1998 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 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.
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.
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. */
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
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]; \
37 if (HAS_HOLES && ch == L'\0' && *inptr != '\0') \
38 { \
39 /* This is an illegal character. */ \
40 result = GCONV_ILLEGAL_INPUT; \
41 break; \
42 } \
44 *((uint32_t *) outptr)++ = ch; \
45 ++inptr; \
47 #include <iconv/loop.c>
50 /* Next, define the other direction. */
51 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
52 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
53 #define LOOPFCT TO_LOOP
54 #define BODY \
55 { \
56 uint32_t ch = *((uint32_t *) inptr); \
58 if (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]) \
59 || (ch != 0 && from_ucs4[ch] == '\0')) \
60 { \
61 /* This is an illegal character. */ \
62 result = GCONV_ILLEGAL_INPUT; \
63 break; \
64 } \
66 *outptr++ = from_ucs4[ch]; \
67 inptr += 4; \
69 #include <iconv/loop.c>
72 /* Now define the toplevel functions. */
73 #include <iconv/skeleton.c>