diff options
author | J. Alexander Treuman <jat@spatialrift.net> | 2007-02-18 00:42:22 +0000 |
---|---|---|
committer | J. Alexander Treuman <jat@spatialrift.net> | 2007-02-18 00:42:22 +0000 |
commit | 7b1e14b8e81c2dc44def58f2781bcfcc3cc9e58b (patch) | |
tree | 16ed8f0c622cc6c9d7569d12c9442992cc23b4b5 /src/path.c | |
parent | d7e8507eaf9ac76d207a51ac850964b9373ba2d3 (diff) |
Reverting all of my localization changes. It was a horrible
implementation, and fixing it is a big enough job that I don't know when
I'll get around to it. Probably best just starting from scratch anyhow.
git-svn-id: https://svn.musicpd.org/mpd/trunk@5373 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/src/path.c b/src/path.c index 0753727ea..118731c5d 100644 --- a/src/path.c +++ b/src/path.c @@ -22,7 +22,6 @@ #include "conf.h" #include "utf8.h" #include "utils.h" -#include "localization.h" #include <stdlib.h> #include <string.h> @@ -32,15 +31,29 @@ #include <errno.h> #include <dirent.h> +#ifdef HAVE_LOCALE +#ifdef HAVE_LANGINFO_CODESET +#include <locale.h> +#include <langinfo.h> +#endif +#endif + const char *musicDir; static const char *playlistDir; static char *fsCharset; +static char *pathConvCharset(char *to, char *from, char *str, char *ret) +{ + if (ret) + free(ret); + return setCharSetConversion(to, from) ? NULL : convStrDup(str); +} + char *fsCharsetToUtf8(char *str) { static char *ret; - ret = convCharset("UTF-8", fsCharset, str, ret); + ret = pathConvCharset("UTF-8", fsCharset, str, ret); if (ret && !validUtf8String(ret)) { free(ret); @@ -54,7 +67,7 @@ char *utf8ToFsCharset(char *str) { static char *ret; - ret = convCharset(fsCharset, "UTF-8", str, ret); + ret = pathConvCharset(fsCharset, "UTF-8", str, ret); if (!ret) ret = xstrdup(str); @@ -122,6 +135,7 @@ void initPaths(void) ConfigParam *fsCharsetParam = getConfigParam(CONF_FS_CHARSET); char *charset = NULL; + char *originalLocale; DIR *dir; musicDir = appendSlash(&(musicParam->value)); @@ -143,10 +157,40 @@ void initPaths(void) } closedir(dir); - if (fsCharsetParam) + if (fsCharsetParam) { charset = xstrdup(fsCharsetParam->value); - else if ((charset = getLocaleCharset())) - charset = xstrdup(charset); + } +#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) { setFsCharset(charset); |