Rather than using a C implementation of memset, directly call memset, which
[glibc.git] / iconvdata / 8bit-gap.c
blobd85d4ad6dbbb446b072b8c532d14ad846394ce63
1 /* Generic conversion to and from 8bit charsets,
2 converting from UCS using gaps.
3 Copyright (C) 1997-2015 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 #include <dlfcn.h>
22 #include <stdint.h>
24 struct gap
26 uint16_t start;
27 uint16_t end;
28 int32_t idx;
31 /* Now we can include the tables. */
32 #include TABLES
34 #ifndef NONNUL
35 # define NONNUL(c) ((c) != '\0')
36 #endif
39 #define FROM_LOOP from_gap
40 #define TO_LOOP to_gap
41 #define DEFINE_INIT 1
42 #define DEFINE_FINI 1
43 #define MIN_NEEDED_FROM 1
44 #define MIN_NEEDED_TO 4
45 #define ONE_DIRECTION 0
48 /* First define the conversion function from the 8bit charset to UCS4. */
49 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
50 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
51 #define LOOPFCT FROM_LOOP
52 #define BODY \
53 { \
54 uint32_t ch = to_ucs4[*inptr]; \
56 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && NONNUL (*inptr)) \
57 { \
58 /* This is an illegal character. */ \
59 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
60 } \
61 else \
62 { \
63 put32 (outptr, ch); \
64 outptr += 4; \
65 } \
67 ++inptr; \
69 #define LOOP_NEED_FLAGS
70 #define ONEBYTE_BODY \
71 { \
72 uint32_t ch = to_ucs4[c]; \
74 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && NONNUL (c)) \
75 return WEOF; \
76 else \
77 return ch; \
79 #include <iconv/loop.c>
82 /* Next, define the other direction. */
83 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
84 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
85 #define LOOPFCT TO_LOOP
86 #define BODY \
87 { \
88 const struct gap *rp = from_idx; \
89 uint32_t ch = get32 (inptr); \
90 unsigned char res; \
92 if (__glibc_unlikely (ch >= 0xffff)) \
93 { \
94 UNICODE_TAG_HANDLER (ch, 4); \
95 rp = NULL; \
96 } \
97 else \
98 while (ch > rp->end) \
99 ++rp; \
100 if (__builtin_expect (rp == NULL, 0) \
101 || __builtin_expect (ch < rp->start, 0) \
102 || (res = from_ucs4[ch + rp->idx], \
103 __builtin_expect (res, '\1') == '\0' && ch != 0)) \
105 /* This is an illegal character. */ \
106 STANDARD_TO_LOOP_ERR_HANDLER (4); \
109 *outptr++ = res; \
110 inptr += 4; \
112 #define LOOP_NEED_FLAGS
113 #include <iconv/loop.c>
116 /* Now define the toplevel functions. */
117 #include <iconv/skeleton.c>