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.
28 #include <sys/types.h>
37 #include <sys/socket.h>
44 char *parsePath(char *path
)
47 if (!g_path_is_absolute(path
) && path
[0] != '~') {
48 g_warning("\"%s\" is not an absolute path", path
);
50 } else if (path
[0] == '~') {
54 if (path
[1] == '/' || path
[1] == '\0') {
55 const char *user
= config_get_string(CONF_USER
, NULL
);
57 struct passwd
*passwd
= getpwnam(user
);
59 g_warning("no such user %s", user
);
63 home
= passwd
->pw_dir
;
65 home
= g_get_home_dir();
67 g_warning("problems getting home "
73 bool foundSlash
= false;
74 struct passwd
*passwd
;
77 for (c
= path
+ 1; *c
!= '\0' && *c
!= '/'; c
++);
84 passwd
= getpwnam(path
+ 1);
86 g_warning("user \"%s\" not found", path
+ 1);
93 home
= passwd
->pw_dir
;
96 return g_strconcat(home
, path
+ pos
, NULL
);
99 return g_strdup(path
);
106 string_array_contains(const char *const* haystack
, const char *needle
)
108 assert(haystack
!= NULL
);
109 assert(needle
!= NULL
);
111 for (; *haystack
!= NULL
; ++haystack
)
112 if (g_ascii_strcasecmp(*haystack
, needle
) == 0)