1 /* Conversion from UTF-16 to legacy encodings.
2    Copyright (C) 2002, 2006-2007, 2009-2018 Free Software Foundation, Inc.
3 
4    This program is free software: you can redistribute it and/or
5    modify it under the terms of either:
6 
7      * the GNU Lesser General Public License as published by the Free
8        Software Foundation; either version 3 of the License, or (at your
9        option) any later version.
10 
11    or
12 
13      * the GNU General Public License as published by the Free
14        Software Foundation; either version 2 of the License, or (at your
15        option) any later version.
16 
17    or both in parallel, as here.
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    Lesser General Public License for more details.
22 
23    You should have received a copy of the GNU Lesser General Public License
24    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
25 
26 /* Written by Bruno Haible <bruno@clisp.org>.  */
27 
28 #include <config.h>
29 
30 /* Specification.  */
31 #include "uniconv.h"
32 
33 #include <errno.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "striconveha.h"
38 #include "unistr.h"
39 
40 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
41 
42 /* Name of UTF-16 encoding with machine dependent endianness and alignment.  */
43 #if defined _LIBICONV_VERSION || (((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__)
44 # ifdef WORDS_BIGENDIAN
45 #  define UTF16_NAME "UTF-16BE"
46 # else
47 #  define UTF16_NAME "UTF-16LE"
48 # endif
49 #endif
50 
51 #define FUNC u16_strconv_to_encoding
52 #define UNIT uint16_t
53 #define U_TO_U8 u16_to_u8
54 #define U_STRLEN u16_strlen
55 #if defined UTF16_NAME
56 # define UTF_NAME UTF16_NAME
57 # define HAVE_UTF_NAME 1
58 #endif
59 #include "u-strconv-to-enc.h"
60