1 /* Generic conversion to and from 8bit charsets.
2 Copyright (C) 1997-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #define FROM_LOOP from_generic
23 #define TO_LOOP to_generic
26 #define MIN_NEEDED_FROM 1
27 #define MIN_NEEDED_TO 4
28 #define ONE_DIRECTION 0
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
37 uint32_t ch = to_ucs4[*inptr]; \
39 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && *inptr != '\0') \
41 /* This is an illegal character. */ \
42 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
49 #define LOOP_NEED_FLAGS
50 #define ONEBYTE_BODY \
52 uint32_t ch = to_ucs4[c]; \
54 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && c != '\0') \
59 #include <iconv/loop.c>
62 /* Next, define the other direction. */
63 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
64 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
65 #define LOOPFCT TO_LOOP
68 uint32_t ch = get32 (inptr); \
70 if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
71 || (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0)) \
73 UNICODE_TAG_HANDLER (ch, 4); \
75 /* This is an illegal character. */ \
76 STANDARD_TO_LOOP_ERR_HANDLER (4); \
79 *outptr++ = from_ucs4[ch]; \
82 #define LOOP_NEED_FLAGS
83 #include <iconv/loop.c>
86 /* Now define the toplevel functions. */
87 #include <iconv/skeleton.c>