1 /* Charset handling for GNU tar.
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any later
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include <localcharset.h>
34 # define iconv_open(tocode, fromcode) ((iconv_t) -1)
37 # define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ((size_t) 0)
40 # define iconv_close(cd) 0
47 static iconv_t conv_desc[2] = { (iconv_t) -1, (iconv_t) -1 };
50 utf8_init (bool to_utf)
52 if (conv_desc[(int) to_utf] == (iconv_t) -1)
55 conv_desc[(int) to_utf] = iconv_open ("UTF-8", locale_charset ());
57 conv_desc[(int) to_utf] = iconv_open (locale_charset (), "UTF-8");
59 return conv_desc[(int) to_utf];
63 utf8_convert (bool to_utf, char const *input, char **output)
70 iconv_t cd = utf8_init (to_utf);
74 *output = xstrdup (input);
77 else if (cd == (iconv_t)-1)
80 inlen = strlen (input) + 1;
81 outlen = inlen * MB_LEN_MAX + 1;
82 ob = *output = xmalloc (outlen);
83 ib = (char ICONV_CONST *) input;
84 rc = iconv (cd, &ib, &inlen, &ob, &outlen);
91 string_ascii_p (char const *p)