powerpc64: Remove strcspn ifunc from the loader
[glibc.git] / iconvdata / euc-kr.c
blob62b09cb8257431b7c38e0c641579048fce20cf22
1 /* Mapping tables for EUC-KR handling.
2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jungshik Shin <jshin@pantheon.yale.edu>
5 and Ulrich Drepper <drepper@cygnus.com>, 1998.
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 <https://www.gnu.org/licenses/>. */
21 #include <dlfcn.h>
22 #include <stdint.h>
23 #include <ksc5601.h>
26 static inline void
27 __attribute ((always_inline))
28 euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
30 if (ch > 0x9f)
32 if (__builtin_expect (ch, 0) == 0x20a9)
34 /* Half-width Korean Currency WON sign. There is no
35 equivalent in EUC-KR. Some mappings use \x5c because
36 this is what some old Korean ASCII variants used but this
37 is causing problems. We map it to the FULL WIDTH WON SIGN. */
38 cp[0] = '\xa3';
39 cp[1] = '\xdc';
41 else if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0)
42 != __UNKNOWN_10646_CHAR)
44 cp[0] |= 0x80;
45 cp[1] |= 0x80;
47 else
48 cp[0] = cp[1] = '\0';
50 else
52 /* There is no mapping for U005c but we nevertheless map it to
53 \x5c. */
54 cp[0] = (unsigned char) ch;
55 cp[1] = '\0';
60 /* Definitions used in the body of the `gconv' function. */
61 #define CHARSET_NAME "EUC-KR//"
62 #define FROM_LOOP from_euc_kr
63 #define TO_LOOP to_euc_kr
64 #define DEFINE_INIT 1
65 #define DEFINE_FINI 1
66 #define MIN_NEEDED_FROM 1
67 #define MAX_NEEDED_FROM 2
68 #define MIN_NEEDED_TO 4
69 #define ONE_DIRECTION 0
72 /* First define the conversion function from EUC-KR to UCS4. */
73 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
74 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
75 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
76 #define LOOPFCT FROM_LOOP
77 #define BODY \
78 { \
79 uint32_t ch = *inptr; \
81 if (ch <= 0x9f) \
82 ++inptr; \
83 else if (__glibc_unlikely (ch == 0xa0)) \
84 { \
85 /* This is illegal. */ \
86 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
87 } \
88 else \
89 { \
90 /* Two-byte character. First test whether the next byte \
91 is also available. */ \
92 ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0x80); \
93 if (__glibc_unlikely (ch == 0)) \
94 { \
95 /* The second byte is not available. */ \
96 result = __GCONV_INCOMPLETE_INPUT; \
97 break; \
98 } \
99 if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
100 /* This is an illegal character. */ \
101 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
104 put32 (outptr, ch); \
105 outptr += 4; \
107 #define LOOP_NEED_FLAGS
108 #define ONEBYTE_BODY \
110 if (c <= 0x9f) \
111 return c; \
112 else \
113 return WEOF; \
115 #include <iconv/loop.c>
118 /* Next, define the other direction. */
119 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
120 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
121 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
122 #define LOOPFCT TO_LOOP
123 #define BODY \
125 uint32_t ch = get32 (inptr); \
126 unsigned char cp[2]; \
128 /* Decomposing Hangul syllables not available in KS C 5601 into \
129 Jamos should be considered either here or in euckr_from_ucs4() */ \
130 euckr_from_ucs4 (ch, cp); \
132 if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \
134 UNICODE_TAG_HANDLER (ch, 4); \
136 /* Illegal character. */ \
137 STANDARD_TO_LOOP_ERR_HANDLER (4); \
140 *outptr++ = cp[0]; \
141 /* Now test for a possible second byte and write this if possible. */ \
142 if (cp[1] != '\0') \
144 if (__glibc_unlikely (outptr >= outend)) \
146 /* The result does not fit into the buffer. */ \
147 --outptr; \
148 result = __GCONV_FULL_OUTPUT; \
149 break; \
151 *outptr++ = cp[1]; \
154 inptr += 4; \
156 #define LOOP_NEED_FLAGS
157 #include <iconv/loop.c>
160 /* Now define the toplevel functions. */
161 #include <iconv/skeleton.c>