diff options
author | Takamichi Horikawa <takamichiho@gmail.com> | 2018-10-28 23:51:44 +0900 |
---|---|---|
committer | Takamichi Horikawa <takamichiho@gmail.com> | 2018-10-28 23:51:44 +0900 |
commit | 8f72d89b6c39e9f516fda8133db146b01bad4560 (patch) | |
tree | 51998c2de4236a1a6fe0b51d727c02cc01505e21 /common | |
parent | a4b29dd9abf182b74170372a0c3e62188c4a158c (diff) |
SDL update
Diffstat (limited to 'common')
-rw-r--r-- | common/fmplayer_file_unix.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/common/fmplayer_file_unix.c b/common/fmplayer_file_unix.c index 3360577..88f1815 100644 --- a/common/fmplayer_file_unix.c +++ b/common/fmplayer_file_unix.c @@ -6,6 +6,9 @@ #include <dirent.h> #include <string.h> #include <strings.h> +#include <iconv.h> +#include <locale.h> +#include <langinfo.h> static void *fileread(const char *path, size_t maxsize, size_t *filesize, enum fmplayer_file_error *error) { FILE *f = 0; @@ -126,7 +129,45 @@ void *fmplayer_path_dup(const void *path) { return strdup(path); } -char *fmplayer_path_filename_sjis(const void *path) { - (void)path; - return 0; +char *fmplayer_path_filename_sjis(const void *pathptr) { + char *path = (char *)pathptr; + locale_t loc = 0; + iconv_t ic = (iconv_t)-1; + char *pathbuf = 0; + char *fname = strrchr(path, '/'); + if (fname) { + if (*fname) fname++; + } else { + fname = path; + } + // use locale from environment values (to guess filesystem path encoding) + loc = newlocale(LC_CTYPE_MASK, "", 0); + if (!loc) { + //perror("newlocale"); + goto err; + } + const int pathbuflen = 160; + pathbuf = malloc(pathbuflen); + if (!pathbuf) goto err; + ic = iconv_open("SHIFT_JIS", nl_langinfo_l(CODESET, loc)); + if (ic == (iconv_t)-1) { + //perror("iconv_open"); + goto err; + } + char *src = fname, *dst = pathbuf; + size_t srcleft = strlen(fname); + size_t dstleft = pathbuflen; + if (iconv(ic, &src, &srcleft, &dst, &dstleft) == (size_t)-1) { + //perror("iconv"); + goto err; + } + iconv_close(ic); + *dst = 0; + freelocale(loc); + return pathbuf; +err: + free(pathbuf); + if (ic != (iconv_t)-1) iconv_close(ic); + if (loc) freelocale(loc); + return strdup(fname); } |