From 586a21688f20d5f5f39a304ba21562f94c1b1a56 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Sun, 6 Mar 2005 19:00:58 +0000 Subject: config file change! now 'port' is optional and 'db_file' is required! also, should have better error reporting when failing to open playlist or music directory's, or writing the db, etc git-svn-id: https://svn.musicpd.org/mpd/trunk@3027 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/path.c | 59 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index 1d599bda3..c35be7f04 100644 --- a/src/path.c +++ b/src/path.c @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef HAVE_LOCALE #ifdef HAVE_LANGINFO_CODESET @@ -110,36 +111,52 @@ char * getFsCharset() { return fsCharset; } -void initPaths(char * playlistDirArg, char * musicDirArg) { +static char * appendSlash(char ** path) { + char * temp = *path; + int len = strlen(temp); + + if(temp[len-1] != '/') { + temp = strdup(*path); + free(*path); + *path = malloc(len+2); + memset(*path, 0, len+2); + memcpy(*path, temp, len); + (*path)[len] = '/'; + } + + return * path; +} + +void initPaths() { + ConfigParam * musicParam = parseConfigFilePath(CONF_MUSIC_DIR, 1); + ConfigParam * playlistParam = parseConfigFilePath(CONF_PLAYLIST_DIR, 1); + ConfigParam * fsCharsetParam = getConfigParam(CONF_FS_CHARSET); + char * charset = NULL; char * originalLocale; - struct stat st; - ConfigParam * param; + DIR * dir; - playlistDir = prependCwdToPathDup(playlistDirArg); - if((stat(playlistDir,&st))<0) { - ERROR("problem stat'ing \"%s\": %s\n", playlistDirArg, strerror(errno)); - exit(EXIT_FAILURE); - } - if(!S_ISDIR(st.st_mode)) { - ERROR("\"%s\" is not a directory: %s\n", playlistDirArg, strerror(errno)); - exit(EXIT_FAILURE); - } + musicDir = appendSlash(&musicParam->value); + playlistDir = appendSlash(&playlistParam->value); - musicDir = prependCwdToPathDup(musicDirArg); - if((stat(musicDir,&st))<0) { - ERROR("problem stat'ing \"%s\"\n",musicDirArg); + if((dir = opendir(playlistDir)) == NULL) { + ERROR("cannot open %s \"%s\" (config line %i): %s\n", + CONF_PLAYLIST_DIR, playlistParam->value, + playlistParam->line, strerror(errno)); exit(EXIT_FAILURE); } - if(!S_ISDIR(st.st_mode)) { - ERROR("\"%s\" is not a directory\n",musicDirArg); + closedir(dir); + + if((dir = opendir(musicDir)) == NULL) { + ERROR("cannot open %s \"%s\" (config line %i): %s\n", + CONF_MUSIC_DIR, musicParam->value, + musicParam->line, strerror(errno)); exit(EXIT_FAILURE); } + closedir(dir); - param = getConfigParam(CONF_FS_CHARSET); - - if(param) { - charset = strdup(param->value); + if(fsCharsetParam) { + charset = strdup(fsCharsetParam->value); } #ifdef HAVE_LOCALE #ifdef HAVE_LANGINFO_CODESET -- cgit v1.2.3