diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DatabaseSave.cxx | 13 | ||||
-rw-r--r-- | src/Main.cxx | 3 | ||||
-rw-r--r-- | src/fs/Path.cxx | 26 | ||||
-rw-r--r-- | src/fs/Path.hxx | 16 |
4 files changed, 28 insertions, 30 deletions
diff --git a/src/DatabaseSave.cxx b/src/DatabaseSave.cxx index 2c46f4a5b..dc87c8ddb 100644 --- a/src/DatabaseSave.cxx +++ b/src/DatabaseSave.cxx @@ -62,7 +62,8 @@ db_save_internal(FILE *fp, const Directory *music_root) fprintf(fp, "%s\n", DIRECTORY_INFO_BEGIN); fprintf(fp, DB_FORMAT_PREFIX "%u\n", DB_FORMAT); fprintf(fp, "%s%s\n", DIRECTORY_MPD_VERSION, VERSION); - fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, path_get_fs_charset()); + fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, + Path::GetFSCharset().c_str()); for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) if (!ignore_tag_items[i]) @@ -106,7 +107,7 @@ db_load_internal(TextFile &file, Directory *music_root, GError **error) found_version = true; } else if (g_str_has_prefix(line, DIRECTORY_FS_CHARSET)) { - const char *new_charset, *old_charset; + const char *new_charset; if (found_charset) { g_set_error(error, db_quark(), 0, @@ -117,14 +118,14 @@ db_load_internal(TextFile &file, Directory *music_root, GError **error) found_charset = true; new_charset = line + sizeof(DIRECTORY_FS_CHARSET) - 1; - old_charset = path_get_fs_charset(); - if (old_charset != NULL - && strcmp(new_charset, old_charset)) { + const std::string &old_charset = Path::GetFSCharset(); + if (!old_charset.empty() + && strcmp(new_charset, old_charset.c_str())) { g_set_error(error, db_quark(), 0, "Existing database has charset " "\"%s\" instead of \"%s\"; " "discarding database file", - new_charset, old_charset); + new_charset, old_charset.c_str()); return false; } } else if (g_str_has_prefix(line, DB_TAG_PREFIX)) { diff --git a/src/Main.cxx b/src/Main.cxx index 32374bcca..41327916b 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -417,7 +417,7 @@ int mpd_main(int argc, char *argv[]) GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted); GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted); - path_global_init(); + Path::GlobalInit(); if (!glue_mapper_init(&error)) { g_warning("%s", error->message); @@ -554,7 +554,6 @@ int mpd_main(int argc, char *argv[]) audio_output_all_finish(); volume_finish(); mapper_finish(); - path_global_finish(); delete global_partition; command_finish(); update_global_finish(); diff --git a/src/fs/Path.cxx b/src/fs/Path.cxx index 6d17cd7da..7664e3ac0 100644 --- a/src/fs/Path.cxx +++ b/src/fs/Path.cxx @@ -46,14 +46,14 @@ */ #define MPD_PATH_MAX_UTF8 ((MPD_PATH_MAX - 1) * 4 + 1) -static char *fs_charset; +std::string fs_charset; std::string Path::ToUTF8(const_pointer path_fs) { if (path_fs == nullptr) return std::string(); - GIConv conv = g_iconv_open("utf-8", fs_charset); + GIConv conv = g_iconv_open("utf-8", fs_charset.c_str()); if (conv == reinterpret_cast<GIConv>(-1)) return std::string(); @@ -80,7 +80,7 @@ Path Path::FromUTF8(const char *path_utf8) gchar *p; p = g_convert(path_utf8, -1, - fs_charset, "utf-8", + fs_charset.c_str(), "utf-8", NULL, NULL, NULL); if (p == NULL) /* fall back to UTF-8 */ @@ -103,25 +103,24 @@ IsSupportedCharset(const char *charset) } static void -path_set_fs_charset(const char *charset) +SetFSCharset(const char *charset) { assert(charset != NULL); if (!IsSupportedCharset(charset)) MPD_ERROR("invalid filesystem charset: %s", charset); - g_free(fs_charset); - fs_charset = g_strdup(charset); + fs_charset = charset; - g_debug("path_set_fs_charset: fs charset is: %s", fs_charset); + g_debug("SetFSCharset: fs charset is: %s", fs_charset.c_str()); } -const char *path_get_fs_charset(void) +const std::string &Path::GetFSCharset() { return fs_charset; } -void path_global_init(void) +void Path::GlobalInit() { const char *charset = NULL; @@ -146,14 +145,9 @@ void path_global_init(void) } if (charset) { - path_set_fs_charset(charset); + SetFSCharset(charset); } else { g_message("setting filesystem charset to ISO-8859-1"); - path_set_fs_charset("ISO-8859-1"); + SetFSCharset("ISO-8859-1"); } } - -void path_global_finish(void) -{ - g_free(fs_charset); -} diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx index 3d5bd868b..b9754b5c5 100644 --- a/src/fs/Path.hxx +++ b/src/fs/Path.hxx @@ -44,12 +44,6 @@ # endif #endif -void path_global_init(); - -void path_global_finish(); - -const char *path_get_fs_charset(); - /** * A path name in the native file system character set. */ @@ -166,6 +160,16 @@ public: static std::string ToUTF8(const_pointer path_fs); /** + * Performs global one-time initialization of this class. + */ + static void GlobalInit(); + + /** + * Gets file system character set name. + */ + static const std::string &GetFSCharset(); + + /** * Copy a #Path object. */ Path &operator=(const Path &other) { |