1 /* plugin_common - Routines common to several plugins
2 * Copyright (C) 2002 Josh Coalson
4 * Only slightly modified charset.c from:
5 * EasyTAG - Tag editor for MP3 and OGG files
6 * Copyright (C) 1999-2001 Håvard Kvålen <havardk@xmms.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_LANGINFO_CODESET
42 char* FLAC_plugin__charset_get_current (void)
44 char *charset = getenv("CHARSET");
46 #ifdef HAVE_LANGINFO_CODESET
48 charset = nl_langinfo(CODESET);
51 charset = "ISO-8859-1";
58 char* FLAC_plugin__charset_convert_string (const char *string, char *from, char *to)
60 size_t outleft, outsize, length;
63 const char *input = string;
68 length = strlen(string);
70 if ((cd = iconv_open(to, from)) == (iconv_t)-1)
73 fprintf(stderr, "convert_string(): Conversion not supported. Charsets: %s -> %s", from, to);
75 return strdup(string);
78 /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
79 /* + 1 for nul in case len == 1 */
80 outsize = ((length + 3) & ~3) + 1;
81 out = malloc(outsize);
82 outleft = outsize - 1;
86 if (iconv(cd, &input, &length, &outptr, &outleft) == -1)
93 outsize = (outsize - 1) * 2 + 1;
94 out = realloc(out, outsize);
96 outleft = outsize - 1 - used;
101 /* Invalid sequence, try to get the rest of the string */
103 length = strlen(input);
107 fprintf(stderr, "convert_string(): Conversion failed. Inputstring: %s; Error: %s", string, strerror(errno));
118 char* FLAC_plugin__charset_convert_string (const char *string, char *from, char *to)
120 (void)from, (void)to;
123 return strdup(string);
128 int FLAC_plugin__charset_test_conversion (char *from, char *to)
132 if ((cd=iconv_open(to,from)) == (iconv_t)-1)
134 /* Conversion not supported */
141 int FLAC_plugin__charset_test_conversion (char *from, char *to)
143 (void)from, (void)to;