Use get16, get32, put16, and put32 instead of direct casting pointer
[kopensolaris-gnu/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 && ch == L'\0' && *inptr != '\0')                           \
38       {                                                                       \
39         /* This is an illegal character.  */                                  \
40         result = __GCONV_ILLEGAL_INPUT;                                       \
41         break;                                                                \
42       }                                                                       \
43                                                                               \
44     put32 (outptr, ch);                                                       \
45     outptr += 4;                                                              \
46     ++inptr;                                                                  \
47   }
48 #include <iconv/loop.c>
49
50
51 /* Next, define the other direction.  */
52 #define MIN_NEEDED_INPUT        MIN_NEEDED_TO
53 #define MIN_NEEDED_OUTPUT       MIN_NEEDED_FROM
54 #define LOOPFCT                 TO_LOOP
55 #define BODY \
56   {                                                                           \
57     uint32_t ch = get32 (inptr);                                              \
58                                                                               \
59     if (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0])                      \
60         || (ch != 0 && from_ucs4[ch] == '\0'))                                \
61       {                                                                       \
62         /* This is an illegal character.  */                                  \
63         result = __GCONV_ILLEGAL_INPUT;                                       \
64         break;                                                                \
65       }                                                                       \
66                                                                               \
67     *outptr++ = from_ucs4[ch];                                                \
68     inptr += 4;                                                               \
69   }
70 #include <iconv/loop.c>
71
72
73 /* Now define the toplevel functions.  */
74 #include <iconv/skeleton.c>