aboutsummaryrefslogtreecommitdiffstats
path: root/src/path.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-04-13 04:59:57 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-04-13 04:59:57 +0000
commit1004890e253453faba81126028986f075e5fc5e7 (patch)
tree053e319b9c64d0b4a47bd61311007f01150109a7 /src/path.c
parent0927c61533d410ffce6c34f279e1280edab0fbd6 (diff)
downloadmpd-1004890e253453faba81126028986f075e5fc5e7.tar.gz
mpd-1004890e253453faba81126028986f075e5fc5e7.tar.xz
mpd-1004890e253453faba81126028986f075e5fc5e7.zip
lots of fsCharset, utf8/ascii converting clean-up and robustness stuff
Also, if fsCharsetToUtf8 can't convert to valid UTF-8, then don't add it to the db, this way clients don't have to worry about weirdness and it will force ppl to convert it. git-svn-id: https://svn.musicpd.org/mpd/trunk@711 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/path.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/path.c b/src/path.c
index e209b671d..db41ed968 100644
--- a/src/path.c
+++ b/src/path.c
@@ -20,6 +20,7 @@
#include "log.h"
#include "charConv.h"
#include "conf.h"
+#include "utf8.h"
#include <stdlib.h>
#include <string.h>
@@ -46,24 +47,35 @@ char * pathConvCharset(char * to, char * from, char * str, char * ret) {
ret = convStrDup(str);
}
- if(!ret) ret = strdup(str);
-
return ret;
}
char * fsCharsetToUtf8(char * str) {
static char * ret = NULL;
- return ret = pathConvCharset("UTF-8",fsCharset,str,ret);
+ ret = pathConvCharset("UTF-8",fsCharset,str,ret);
+
+ if(ret && !validUtf8String(ret)) ret = NULL;
+ /*if(!ret) ret = asciiStrToUtf8Dup(str);*/
+
+ /* if all else fails, just strdup */
+
+ return ret;
}
char * utf8ToFsCharset(char * str) {
static char * ret = NULL;
- return ret = pathConvCharset(fsCharset,"UTF-8",str,ret);
+ ret = pathConvCharset(fsCharset,"UTF-8",str,ret);
+
+ if(!ret) ret = strdup(str);
+
+ return ret;
}
void setFsCharset(char * charset) {
+ int error = 0;
+
if(fsCharset) free(fsCharset);
fsCharset = strdup(charset);
@@ -74,11 +86,19 @@ void setFsCharset(char * charset) {
ERROR("fs charset conversion problem: "
"not able to convert from \"%s\" to \"%s\"\n",
fsCharset,"UTF-8");
+ error = 1;
}
if(setCharSetConversion(fsCharset,"UTF-8")!=0) {
ERROR("fs charset conversion problem: "
"not able to convert from \"%s\" to \"%s\"\n",
"UTF-8",fsCharset);
+ error = 1;
+ }
+
+ if(error) {
+ free(fsCharset);
+ ERROR("setting fs charset to ISO-8859-1!\n");
+ fsCharset = strdup("ISO-8859-1");
}
}