1 /* Charset handling for GNU tar.
3 Copyright 2004, 2006-2007, 2013 Free Software Foundation, Inc.
5 This file is part of GNU tar.
7 GNU tar is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 GNU tar is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include <localcharset.h>
35 # define iconv_open(tocode, fromcode) ((iconv_t) -1)
38 # define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ((size_t) 0)
41 # define iconv_close(cd) 0
48 static iconv_t conv_desc[2] = { (iconv_t) -1, (iconv_t) -1 };
51 utf8_init (bool to_utf)
53 if (conv_desc[(int) to_utf] == (iconv_t) -1)
56 conv_desc[(int) to_utf] = iconv_open ("UTF-8", locale_charset ());
58 conv_desc[(int) to_utf] = iconv_open (locale_charset (), "UTF-8");
60 return conv_desc[(int) to_utf];
64 utf8_convert (bool to_utf, char const *input, char **output)
71 iconv_t cd = utf8_init (to_utf);
75 *output = xstrdup (input);
78 else if (cd == (iconv_t)-1)
81 inlen = strlen (input) + 1;
82 outlen = inlen * MB_LEN_MAX + 1;
83 ob = *output = xmalloc (outlen);
84 ib = (char ICONV_CONST *) input;
85 rc = iconv (cd, &ib, &inlen, &ob, &outlen);
92 string_ascii_p (char const *p)