Commit 6a7a26fe authored by Max Kellermann's avatar Max Kellermann

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.
parent 3002fd18
......@@ -23,13 +23,6 @@
#include "playlist.h"
#include "os_compat.h"
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO_CODESET
#include <locale.h>
#include <langinfo.h>
#endif
#endif
#include <glib.h>
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);
}
#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");
}
}
const gchar **encodings;
g_get_filename_charsets(&encodings);
free(originalLocale);
} else
WARNING("problems getting locale with setlocale()\n");
#endif
#endif
if (encodings[0] != NULL && *encodings[0] != '\0')
charset = g_strdup(encodings[0]);
}
if (charset) {
path_set_fs_charset(charset);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment