aboutsummaryrefslogtreecommitdiffstats
path: root/support.c
diff options
context:
space:
mode:
authorKalle Wallin <kaw@linux.se>2004-03-22 12:43:30 +0000
committerKalle Wallin <kaw@linux.se>2004-03-22 12:43:30 +0000
commitd15752f082af7e941cc55f5f71ea5cff1a6b4653 (patch)
tree5391e54252658231b8921e07643fedbcf568fc7e /support.c
parent4906ff467fb9c0cccd592ce6c0656e3271444263 (diff)
downloadmpd-d15752f082af7e941cc55f5f71ea5cff1a6b4653.tar.gz
mpd-d15752f082af7e941cc55f5f71ea5cff1a6b4653.tar.xz
mpd-d15752f082af7e941cc55f5f71ea5cff1a6b4653.zip
Updated charset support
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@364 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'support.c')
-rw-r--r--support.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/support.c b/support.c
index d2dc9759c..15f084c1c 100644
--- a/support.c
+++ b/support.c
@@ -5,31 +5,35 @@
#include <glib.h>
#include "config.h"
+#include "support.h"
#ifdef HAVE_LOCALE_H
-#ifdef HAVE_LANGINFO_H
-#ifdef HAVE_ICONV
#include <locale.h>
-#include <langinfo.h>
-#include <iconv.h>
-#define ENABLE_CHARACTER_SET_CONVERSION
-#endif
#endif
+
+#ifdef HAVE_ICONV
+#include <iconv.h>
#endif
-#include "support.h"
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
#define BUFSIZE 1024
-#ifdef ENABLE_CHARACTER_SET_CONVERSION
-static char *locale = NULL;
+
static char *charset = NULL;
+
+#ifdef HAVE_LOCALE_H
+static char *locale = NULL;
+#endif
+
+#ifdef HAVE_ICONV
iconv_t iconv_from_uft8 = (iconv_t)(-1);
iconv_t iconv_to_uft8 = (iconv_t)(-1);
#endif
-
#ifndef HAVE_LIBGEN_H
char *
@@ -71,21 +75,28 @@ basename(char *path)
int
charset_init(void)
{
-#ifdef ENABLE_CHARACTER_SET_CONVERSION
+#ifdef HAVE_LOCALE_H
/* get current locale */
if( (locale=setlocale(LC_CTYPE,"")) == NULL )
{
fprintf(stderr,"setlocale() - failed!\n");
return -1;
}
+#endif
+#ifdef HAVE_LANGINFO_CODESET
/* get charset */
if( (charset=nl_langinfo(CODESET)) == NULL )
{
- fprintf(stderr,"nl_langinfo() - failed!\n");
- return -1;
+ fprintf(stderr,
+ "nl_langinfo() failed using default:" DEFAULT_CHARSET "\n");
}
-
+#endif
+
+ if( charset==NULL )
+ charset = DEFAULT_CHARSET;
+
+#ifdef HAVE_ICONV
/* allocate descriptor for character set conversion */
iconv_from_uft8 = iconv_open(charset, "UTF-8");
if( iconv_from_uft8 == (iconv_t)(-1) )
@@ -101,7 +112,7 @@ charset_init(void)
int
charset_close(void)
{
-#ifdef ENABLE_CHARACTER_SET_CONVERSION
+#ifdef HAVE_ICONV
if( iconv_from_uft8 == (iconv_t)(-1) )
{
iconv_close(iconv_from_uft8);
@@ -121,7 +132,7 @@ charset_close(void)
char *
utf8_to_locale(char *str)
{
-#ifdef ENABLE_CHARACTER_SET_CONVERSION
+#ifdef HAVE_ICONV
size_t inleft;
size_t retlen;
char *ret;