diff --git a/support.c b/support.c
index d2dc9759c7e173f94a0535dce9dd96807e2efd5e..15f084c1cd84afb006ab604bc6ff55f7255e91d4 100644 (file)
--- a/support.c
+++ b/support.c
#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 *
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) )
int
charset_close(void)
{
-#ifdef ENABLE_CHARACTER_SET_CONVERSION
+#ifdef HAVE_ICONV
if( iconv_from_uft8 == (iconv_t)(-1) )
{
iconv_close(iconv_from_uft8);
char *
utf8_to_locale(char *str)
{
-#ifdef ENABLE_CHARACTER_SET_CONVERSION
+#ifdef HAVE_ICONV
size_t inleft;
size_t retlen;
char *ret;