2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #define G_LOG_DOMAIN "path"
32 static char *fs_charset
;
35 fs_charset_to_utf8(const char *path_fs
)
37 return g_convert(path_fs
, -1,
43 utf8_to_fs_charset(const char *path_utf8
)
47 p
= g_convert(path_utf8
, -1,
51 /* fall back to UTF-8 */
52 p
= g_strdup(path_utf8
);
58 path_set_fs_charset(const char *charset
)
62 assert(charset
!= NULL
);
64 /* convert a space to ensure that the charset is valid */
65 test
= g_convert(" ", 1, charset
, "UTF-8", NULL
, NULL
, NULL
);
67 g_error("invalid filesystem charset: %s", charset
);
71 fs_charset
= g_strdup(charset
);
73 g_debug("path_set_fs_charset: fs charset is: %s", fs_charset
);
76 const char *path_get_fs_charset(void)
81 void path_global_init(void)
83 const char *charset
= NULL
;
85 charset
= config_get_string(CONF_FS_CHARSET
, NULL
);
86 if (charset
== NULL
) {
87 const gchar
**encodings
;
88 g_get_filename_charsets(&encodings
);
90 if (encodings
[0] != NULL
&& *encodings
[0] != '\0')
91 charset
= encodings
[0];
95 path_set_fs_charset(charset
);
97 g_message("setting filesystem charset to ISO-8859-1");
98 path_set_fs_charset("ISO-8859-1");
102 void path_global_finish(void)