1 /* plugin_common - Routines common to several plugins
2 * Copyright (C) 2002,2003 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.
36 #ifdef HAVE_LANGINFO_CODESET
47 char* FLAC_plugin__charset_get_current (void)
49 char *charset = getenv("CHARSET");
51 #ifdef HAVE_LANGINFO_CODESET
53 charset = nl_langinfo(CODESET);
56 charset = "ISO-8859-1";
63 char* FLAC_plugin__charset_convert_string (const char *string, char *from, char *to)
65 size_t outleft, outsize, length;
68 const char *input = string;
73 length = strlen(string);
75 if ((cd = iconv_open(to, from)) == (iconv_t)-1)
78 fprintf(stderr, "convert_string(): Conversion not supported. Charsets: %s -> %s", from, to);
80 return strdup(string);
83 /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
84 /* + 1 for nul in case len == 1 */
85 outsize = ((length + 3) & ~3) + 1;
86 out = malloc(outsize);
87 outleft = outsize - 1;
91 if (iconv(cd, (char**)&input, &length, &outptr, &outleft) == -1)
98 outsize = (outsize - 1) * 2 + 1;
99 out = realloc(out, outsize);
101 outleft = outsize - 1 - used;
106 /* Invalid sequence, try to get the rest of the string */
108 length = strlen(input);
112 fprintf(stderr, "convert_string(): Conversion failed. Inputstring: %s; Error: %s", string, strerror(errno));
123 char* FLAC_plugin__charset_convert_string (const char *string, char *from, char *to)
125 (void)from, (void)to;
128 return strdup(string);
133 int FLAC_plugin__charset_test_conversion (char *from, char *to)
137 if ((cd=iconv_open(to,from)) == (iconv_t)-1)
139 /* Conversion not supported */
146 int FLAC_plugin__charset_test_conversion (char *from, char *to)
148 (void)from, (void)to;