aboutsummaryrefslogtreecommitdiffstats
path: root/src/fs/Path.cxx
diff options
context:
space:
mode:
authorDenis Krjuchkov <denis@crazydev.net>2013-01-24 02:26:38 +0600
committerDenis Krjuchkov <denis@crazydev.net>2013-01-28 00:13:45 +0600
commit3c7cf94643bc45237d1e61c4e6015d498e4400b0 (patch)
treebe93d9088f7b8199b0d07cce56017e6726a47f76 /src/fs/Path.cxx
parent3bd35d188320f20a98a1004c001b132fc0975437 (diff)
downloadmpd-3c7cf94643bc45237d1e61c4e6015d498e4400b0.tar.gz
mpd-3c7cf94643bc45237d1e61c4e6015d498e4400b0.tar.xz
mpd-3c7cf94643bc45237d1e61c4e6015d498e4400b0.zip
Path: convert fs_charset_to_utf8() to static method Path::ToUTF8()
Diffstat (limited to 'src/fs/Path.cxx')
-rw-r--r--src/fs/Path.cxx35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/fs/Path.cxx b/src/fs/Path.cxx
index 294f60781..0590fbd8f 100644
--- a/src/fs/Path.cxx
+++ b/src/fs/Path.cxx
@@ -48,24 +48,31 @@
static char *fs_charset;
-std::string Path::ToUTF8() const
+std::string Path::ToUTF8(const_pointer path_fs)
{
- if (value == nullptr)
+ if (path_fs == nullptr)
return std::string();
- char *path_utf8 = fs_charset_to_utf8(value);
- if (path_utf8 == nullptr)
+
+ GIConv conv = g_iconv_open("utf-8", fs_charset);
+ if (conv == reinterpret_cast<GIConv>(-1))
return std::string();
- std::string result = value;
- g_free(path_utf8);
- return value;
-}
-char *
-fs_charset_to_utf8(const char *path_fs)
-{
- return g_convert(path_fs, -1,
- "utf-8", fs_charset,
- NULL, NULL, NULL);
+ // g_iconv() does not need nul-terminator,
+ // std::string could be created without it too.
+ char path_utf8[MPD_PATH_MAX_UTF8 - 1];
+ char *in = const_cast<char *>(path_fs);
+ char *out = path_utf8;
+ size_t in_left = strlen(path_fs);
+ size_t out_left = sizeof(path_utf8);
+
+ size_t ret = g_iconv(conv, &in, &in_left, &out, &out_left);
+
+ g_iconv_close(conv);
+
+ if (ret == static_cast<size_t>(-1) || in_left > 0)
+ return std::string();
+
+ return std::string(path_utf8, sizeof(path_utf8) - out_left);
}
char *