configure.ac: Don't allow UNIX IPC to be configured for a native Windows build.
[mpd-mk.git] / src / path.c
blob96c429529653c24f69c03ab42dd731f244b2dfe8
1 /*
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.
20 #include "config.h"
21 #include "path.h"
22 #include "conf.h"
24 #include <glib.h>
26 #include <assert.h>
27 #include <string.h>
29 #undef G_LOG_DOMAIN
30 #define G_LOG_DOMAIN "path"
32 static char *fs_charset;
34 char *
35 fs_charset_to_utf8(const char *path_fs)
37 return g_convert(path_fs, -1,
38 "utf-8", fs_charset,
39 NULL, NULL, NULL);
42 char *
43 utf8_to_fs_charset(const char *path_utf8)
45 gchar *p;
47 p = g_convert(path_utf8, -1,
48 fs_charset, "utf-8",
49 NULL, NULL, NULL);
50 if (p == NULL)
51 /* fall back to UTF-8 */
52 p = g_strdup(path_utf8);
54 return p;
57 static void
58 path_set_fs_charset(const char *charset)
60 char *test;
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);
66 if (test == NULL)
67 g_error("invalid filesystem charset: %s", charset);
68 g_free(test);
70 g_free(fs_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)
78 return fs_charset;
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];
94 if (charset) {
95 path_set_fs_charset(charset);
96 } else {
97 g_message("setting filesystem charset to ISO-8859-1");
98 path_set_fs_charset("ISO-8859-1");
102 void path_global_finish(void)
104 g_free(fs_charset);