/* Generic conversion to and from ANSI_X3.110-1983.
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
#include <dlfcn.h>
#include <gconv.h>
#define MIN_NEEDED_FROM 1
#define MAX_NEEDED_FROM 2
#define MIN_NEEDED_TO 4
+#define ONE_DIRECTION 0
/* First define the conversion function from ANSI_X3.110 to UCS4. */
#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
uint32_t ch = *inptr; \
int incr; \
\
- if (__builtin_expect (ch, 0x00) >= 0xc1 && ch <= 0xcf) \
+ if (__builtin_expect (ch >= 0xc1, 0) && ch <= 0xcf) \
{ \
- /* Composed character. First test whether the next character \
+ /* Composed character. First test whether the next byte \
is also available. */ \
uint32_t ch2; \
\
\
ch2 = inptr[1]; \
\
- if (__builtin_expect (ch2, 0x20) < 0x20 \
- || __builtin_expect (ch2, 0x7f) >= 0x80) \
+ if (__builtin_expect (ch2 < 0x20, 0) \
+ || __builtin_expect (ch2 >= 0x80, 0)) \
{ \
/* This is illegal. */ \
- if (! ignore_errors_p ()) \
- { \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- ++*irreversible; \
- incr = 1; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
else \
{ \
incr = 1; \
} \
\
- if (__builtin_expect (ch, 1) == 0 && *inptr != '\0') \
+ if (__builtin_expect (ch == 0, 0) && *inptr != '\0') \
{ \
/* This is an illegal character. */ \
- if (! ignore_errors_p ()) \
- { \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
+ STANDARD_FROM_LOOP_ERR_HANDLER (incr); \
} \
else \
{ \
inptr += incr; \
}
#define LOOP_NEED_FLAGS
+#define ONEBYTE_BODY \
+ { \
+ uint32_t ch = to_ucs4[c]; \
+ \
+ if (__builtin_expect (ch == 0, 0) && c != '\0') \
+ return WEOF; \
+ else \
+ return ch; \
+ }
#include <iconv/loop.c>
uint32_t ch = get32 (inptr); \
const char *cp; \
\
- if (__builtin_expect (ch, 0) \
- >= sizeof (from_ucs4) / sizeof (from_ucs4[0])) \
+ if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \
+ 0)) \
{ \
if (ch == 0x2c7) \
cp = "\xcf\x20"; \
if (tmp[0] == '\0') \
{ \
/* Illegal characters. */ \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
tmp[1] = '\0'; \
cp = tmp; \
if (tmp[0] == '\0') \
{ \
/* Illegal characters. */ \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
tmp[1] = '\0'; \
cp = tmp; \
cp = "\xd5"; \
else \
{ \
+ UNICODE_TAG_HANDLER (ch, 4); \
+ \
/* Illegal characters. */ \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
} \
else \
if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \
{ \
/* Illegal characters. */ \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
} \
\
/* Now test for a possible second byte and write this if possible. */ \
if (cp[1] != '\0') \
{ \
- if (__builtin_expect (outptr >= outend, 0)) \
+ if (__glibc_unlikely (outptr >= outend)) \
{ \
/* The result does not fit into the buffer. */ \
--outptr; \