Commit 2e086ee4 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Fix iconv conversion from UTF8 to UTF8 on Android and possibly others

parent 297f63c7
......@@ -58,13 +58,17 @@ static char *utf8_convert(const char *filename){
size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
iconv_t cb;
strncpy(db_file_locale, filename, MAX_PATH_SIZE-1);
cb = iconv_open("UTF-8", nl_langinfo(CODESET));
if(cb != (iconv_t)-1) {
int ret;
ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
if(ret == -1) db_file_utf8[0] = '\0';
iconv_close(cb);
if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) {
strncpy(db_file_utf8, filename, MAX_PATH_SIZE - 1);
} else {
strncpy(db_file_locale, filename, MAX_PATH_SIZE-1);
cb = iconv_open("UTF-8", nl_langinfo(CODESET));
if (cb != (iconv_t)-1) {
int ret;
ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
if(ret == -1) db_file_utf8[0] = '\0';
iconv_close(cb);
}
}
#endif
return ms_strdup(db_file_utf8);
......
......@@ -260,7 +260,7 @@ static char* ConvertFromUtf8Filename(const char* fName){
bctbx_free(wideFilename);
return convertedFilename;
#elif defined(__QNXNTO__)
return bctbx_strdup(fName);
return bctbx_strdup(fName);
#else
#define MAX_PATH_SIZE 1024
char db_file_utf8[MAX_PATH_SIZE] = {'\0'};
......@@ -269,13 +269,17 @@ static char* ConvertFromUtf8Filename(const char* fName){
size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
iconv_t cb;
strncpy(db_file_utf8, fName, MAX_PATH_SIZE-1);
cb = iconv_open(nl_langinfo(CODESET), "UTF-8");
if(cb != (iconv_t)-1) {
int ret;
ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
if(ret == -1) db_file_locale[0] = '\0';
iconv_close(cb);
if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) {
strncpy(db_file_locale, fName, MAX_PATH_SIZE - 1);
} else {
strncpy(db_file_utf8, fName, MAX_PATH_SIZE-1);
cb = iconv_open(nl_langinfo(CODESET), "UTF-8");
if (cb != (iconv_t)-1) {
int ret;
ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
if(ret == -1) db_file_locale[0] = '\0';
iconv_close(cb);
}
}
return bctbx_strdup(db_file_locale);
#endif
......
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