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