]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/8bit-generic.c
2014-05-01 Steve Ellcey <sellcey@mips.com>
[thirdparty/glibc.git] / iconvdata / 8bit-generic.c
CommitLineData
04be94a8 1/* Generic conversion to and from 8bit charsets.
d4697bc9 2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
f4017d20
UD
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
41bdb6e2
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
f4017d20
UD
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
41bdb6e2 14 Lesser General Public License for more details.
f4017d20 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
f4017d20 19
55985355 20#include <dlfcn.h>
e054f494 21#include <stdint.h>
55985355 22
8619129f
UD
23#define FROM_LOOP from_generic
24#define TO_LOOP to_generic
25#define DEFINE_INIT 1
26#define DEFINE_FINI 1
27#define MIN_NEEDED_FROM 1
28#define MIN_NEEDED_TO 4
0cdddc25 29#define ONE_DIRECTION 0
8619129f
UD
30
31
32/* First define the conversion function from the 8bit charset to UCS4. */
33#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
34#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
35#define LOOPFCT FROM_LOOP
36#define BODY \
37 { \
38 uint32_t ch = to_ucs4[*inptr]; \
39 \
e438a468 40 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && *inptr != '\0') \
8619129f
UD
41 { \
42 /* This is an illegal character. */ \
e438a468 43 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
8619129f
UD
44 } \
45 \
77e1d15a
UD
46 put32 (outptr, ch); \
47 outptr += 4; \
8619129f
UD
48 ++inptr; \
49 }
55985355 50#define LOOP_NEED_FLAGS
f9ad060c
UD
51#define ONEBYTE_BODY \
52 { \
53 uint32_t ch = to_ucs4[c]; \
54 \
55 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && c != '\0') \
56 return WEOF; \
57 else \
58 return ch; \
59 }
8619129f
UD
60#include <iconv/loop.c>
61
62
63/* Next, define the other direction. */
64#define MIN_NEEDED_INPUT MIN_NEEDED_TO
65#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
66#define LOOPFCT TO_LOOP
67#define BODY \
68 { \
77e1d15a 69 uint32_t ch = get32 (inptr); \
8619129f 70 \
5ea1a82d
UD
71 if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
72 || (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0)) \
8619129f 73 { \
601d2942
UD
74 UNICODE_TAG_HANDLER (ch, 4); \
75 \
8619129f 76 /* This is an illegal character. */ \
e438a468 77 STANDARD_TO_LOOP_ERR_HANDLER (4); \
55985355 78 } \
d6204268
UD
79 \
80 *outptr++ = from_ucs4[ch]; \
81 inptr += 4; \
8619129f 82 }
55985355 83#define LOOP_NEED_FLAGS
8619129f
UD
84#include <iconv/loop.c>
85
86
87/* Now define the toplevel functions. */
88#include <iconv/skeleton.c>