diff options
author | Max Kellermann <max@duempel.org> | 2009-01-08 21:20:46 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-08 21:20:46 +0100 |
commit | 5ed5aa99acb6b8360df75bb1ce13d4b97ea50538 (patch) | |
tree | 518a01dabc3c9652fdbb090eb4e8fd97ed725729 /src/path.c | |
parent | f0980283bcce8ad7819f71bc49b973e28e54b22d (diff) | |
download | mpd-5ed5aa99acb6b8360df75bb1ce13d4b97ea50538.tar.gz mpd-5ed5aa99acb6b8360df75bb1ce13d4b97ea50538.tar.xz mpd-5ed5aa99acb6b8360df75bb1ce13d4b97ea50538.zip |
path: allocate buffer in fs_charset conversion functions
Don't use fixed static buffers. GLib allocates a new string for us
anyway, let's just return this one instead of copying it.
Diffstat (limited to '')
-rw-r--r-- | src/path.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/path.c b/src/path.c index 88ac9382e..fe602a15f 100644 --- a/src/path.c +++ b/src/path.c @@ -29,36 +29,27 @@ static char *fs_charset; -char *fs_charset_to_utf8(char *dst, const char *str) +char * +fs_charset_to_utf8(const char *path_fs) { - gchar *p; - - p = g_convert(str, -1, - "utf-8", fs_charset, - NULL, NULL, NULL); - if (p == NULL) - /* no fallback */ - return NULL; - - g_strlcpy(dst, p, MPD_PATH_MAX); - g_free(p); - return dst; + return g_convert(path_fs, -1, + "utf-8", fs_charset, + NULL, NULL, NULL); } -char *utf8_to_fs_charset(char *dst, const char *str) +char * +utf8_to_fs_charset(const char *path_utf8) { gchar *p; - p = g_convert(str, -1, + p = g_convert(path_utf8, -1, fs_charset, "utf-8", NULL, NULL, NULL); if (p == NULL) /* fall back to UTF-8 */ - return strcpy(dst, str); + p = g_strdup(path_utf8); - g_strlcpy(dst, p, MPD_PATH_MAX); - g_free(p); - return dst; + return p; } void path_set_fs_charset(const char *charset) |