aboutsummaryrefslogtreecommitdiffstats
path: root/src/database.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-20 22:18:40 +0200
committerMax Kellermann <max@duempel.org>2008-10-20 22:18:40 +0200
commit49260e6db20aa865e485a02fae5c0249d1df0d8a (patch)
tree03446e4b7e117e87d048d2e36ad199b68cefe752 /src/database.c
parentba96920a52bbd2208aa1f3b284edc864e26198ce (diff)
downloadmpd-49260e6db20aa865e485a02fae5c0249d1df0d8a.tar.gz
mpd-49260e6db20aa865e485a02fae5c0249d1df0d8a.tar.xz
mpd-49260e6db20aa865e485a02fae5c0249d1df0d8a.zip
path: replaced parent_path() with g_path_get_dirname()
Again, GLib's version is more robust than ours.
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/database.c b/src/database.c
index 93ce2e96b..74a3a3e3c 100644
--- a/src/database.c
+++ b/src/database.c
@@ -33,6 +33,7 @@
#include <assert.h>
#include <string.h>
+#include <glib.h>
static struct directory *music_root;
@@ -151,19 +152,18 @@ db_check(void)
/* If the file doesn't exist, we can't check if we can write
* it, so we are going to try to get the directory path, and
* see if we can write a file in that */
- char dirPath[MPD_PATH_MAX];
- parent_path(dirPath, dbFile);
- if (*dirPath == '\0')
- strcpy(dirPath, "/");
+ char *dirPath = g_path_get_dirname(dbFile);
/* Check that the parent part of the path is a directory */
if (stat(dirPath, &st) < 0) {
+ g_free(dirPath);
ERROR("Couldn't stat parent directory of db file "
"\"%s\": %s\n", dbFile, strerror(errno));
return -1;
}
if (!S_ISDIR(st.st_mode)) {
+ g_free(dirPath);
ERROR("Couldn't create db file \"%s\" because the "
"parent path is not a directory\n", dbFile);
return -1;
@@ -173,9 +173,12 @@ db_check(void)
if (access(dirPath, R_OK | W_OK)) {
ERROR("Can't create db file in \"%s\": %s\n", dirPath,
strerror(errno));
+ g_free(dirPath);
return -1;
}
+ g_free(dirPath);
+
return 0;
}