From 6a7a26fe42b772347833136666b237ad6d8a51dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 5 Nov 2008 18:25:57 +0100 Subject: path: get filesystem charset from GLib GLib provides the function g_get_filename_charsets() which determines the file system character set. This changes MPD's fallback: GLib prefers UTF-8 as a fallback. MPD used to fall back to ISO Latin 1. --- src/path.c | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/src/path.c b/src/path.c index b3af926ba..7e24fbf8f 100644 --- a/src/path.c +++ b/src/path.c @@ -23,13 +23,6 @@ #include "playlist.h" #include "os_compat.h" -#ifdef HAVE_LOCALE -#ifdef HAVE_LANGINFO_CODESET -#include -#include -#endif -#endif - #include static char *fs_charset; @@ -98,42 +91,16 @@ void path_global_init(void) ConfigParam *fs_charset_param = getConfigParam(CONF_FS_CHARSET); char *charset = NULL; - char *originalLocale; if (fs_charset_param) { charset = xstrdup(fs_charset_param->value); + } else { + const gchar **encodings; + g_get_filename_charsets(&encodings); + + if (encodings[0] != NULL && *encodings[0] != '\0') + charset = g_strdup(encodings[0]); } -#ifdef HAVE_LOCALE -#ifdef HAVE_LANGINFO_CODESET - else if ((originalLocale = setlocale(LC_CTYPE, NULL))) { - char *temp; - char *currentLocale; - originalLocale = xstrdup(originalLocale); - - if (!(currentLocale = setlocale(LC_CTYPE, ""))) { - WARNING("problems setting current locale with " - "setlocale()\n"); - } else { - if (strcmp(currentLocale, "C") == 0 || - strcmp(currentLocale, "POSIX") == 0) { - WARNING("current locale is \"%s\"\n", - currentLocale); - } else if ((temp = nl_langinfo(CODESET))) { - charset = xstrdup(temp); - } else - WARNING - ("problems getting charset for locale\n"); - if (!setlocale(LC_CTYPE, originalLocale)) { - WARNING - ("problems resetting locale with setlocale()\n"); - } - } - - free(originalLocale); - } else - WARNING("problems getting locale with setlocale()\n"); -#endif -#endif if (charset) { path_set_fs_charset(charset); -- cgit v1.2.3