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.
32 #ifdef HAVE_LANGINFO_CODESET
43 char* FLAC_plugin__charset_get_current (void)
45 char *charset = getenv("CHARSET");
47 #ifdef HAVE_LANGINFO_CODESET
49 charset = nl_langinfo(CODESET);
52 charset = "ISO-8859-1";
59 char* FLAC_plugin__charset_convert_string (const char *string, char *from, char *to)
61 size_t outleft, outsize, length;
64 const char *input = string;
69 length = strlen(string);
71 if ((cd = iconv_open(to, from)) == (iconv_t)-1)
74 fprintf(stderr, "convert_string(): Conversion not supported. Charsets: %s -> %s", from, to);
76 return strdup(string);
79 /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
80 /* + 1 for nul in case len == 1 */
81 outsize = ((length + 3) & ~3) + 1;
82 out = malloc(outsize);
83 outleft = outsize - 1;
87 if (iconv(cd, &input, &length, &outptr, &outleft) == -1)
94 outsize = (outsize - 1) * 2 + 1;
95 out = realloc(out, outsize);
97 outleft = outsize - 1 - used;
102 /* Invalid sequence, try to get the rest of the string */
104 length = strlen(input);
108 fprintf(stderr, "convert_string(): Conversion failed. Inputstring: %s; Error: %s", string, strerror(errno));
119 char* FLAC_plugin__charset_convert_string (const char *string, char *from, char *to)
121 (void)from, (void)to;
124 return strdup(string);
129 int FLAC_plugin__charset_test_conversion (char *from, char *to)
133 if ((cd=iconv_open(to,from)) == (iconv_t)-1)
135 /* Conversion not supported */
142 int FLAC_plugin__charset_test_conversion (char *from, char *to)
144 (void)from, (void)to;