From 790e70cf25ade17e7412b153c440ef4999fe72fd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 3 Jan 2008 07:22:22 +0000 Subject: directory.c: get rid of the horrid dirname(3) and libgen.h dependency Ok, so basename(3) is even more brain-damaged, inconsistent and/or broken than dirname(3) on most systems, but there are broken implementations of it out there. Just use our already existing internal parent_path() function instead and get rid of the only place where we look for libgen.h. git-svn-id: https://svn.musicpd.org/mpd/trunk@7129 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/directory.c') diff --git a/src/directory.c b/src/directory.c index b706b4208..45e583d2d 100644 --- a/src/directory.c +++ b/src/directory.c @@ -41,7 +41,6 @@ #include #include #include -#include #define DIRECTORY_DIR "directory: " #define DIRECTORY_MTIME "mtime: " @@ -988,32 +987,26 @@ static void sortDirectory(Directory * directory) int checkDirectoryDB(void) { struct stat st; - char *dbFile; - char *dirPath; - char *dbPath; - - dbFile = getDbFile(); + char *dbFile = getDbFile(); /* Check if the file exists */ if (access(dbFile, F_OK)) { /* 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 */ - dbPath = xstrdup(dbFile); - dirPath = dirname(dbPath); + char dirPath[MPD_PATH_MAX]; + parent_path(dirPath, dbFile); /* Check that the parent part of the path is a directory */ if (stat(dirPath, &st) < 0) { ERROR("Couldn't stat parent directory of db file " "\"%s\": %s\n", dbFile, strerror(errno)); - free(dbPath); return -1; } if (!S_ISDIR(st.st_mode)) { ERROR("Couldn't create db file \"%s\" because the " "parent path is not a directory\n", dbFile); - free(dbPath); return -1; } @@ -1021,12 +1014,9 @@ int checkDirectoryDB(void) if (access(dirPath, R_OK | W_OK)) { ERROR("Can't create db file in \"%s\": %s\n", dirPath, strerror(errno)); - free(dbPath); return -1; - } - free(dbPath); return 0; } -- cgit v1.2.3