aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/directory.c2
-rw-r--r--src/directory.h2
-rw-r--r--src/main.c55
-rw-r--r--src/path.c61
-rw-r--r--src/path.h7
-rw-r--r--src/playlist.c4
6 files changed, 70 insertions, 61 deletions
diff --git a/src/directory.c b/src/directory.c
index f46a6d56e..d7a7d582f 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -70,7 +70,7 @@ typedef struct _Directory {
Directory * mp3rootDirectory = NULL;
-char directorydb[MAXPATHLEN+1];
+char * directorydb;
volatile int directory_updatePid = 0;
diff --git a/src/directory.h b/src/directory.h
index f5af322db..a4daa3f7f 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <sys/param.h>
-extern char directorydb[MAXPATHLEN+1];
+extern char * directorydb;
void readDirectoryDBIfUpdateIsFinished();
diff --git a/src/main.c b/src/main.c
index b7820b2cc..69560dbf3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -195,7 +195,6 @@ void parseOptions(int argc, char ** argv, Options * options) {
int main(int argc, char * argv[]) {
int port, uid, gid;
- struct stat st;
FILE * out;
FILE * err;
Options options;
@@ -301,61 +300,15 @@ int main(int argc, char * argv[]) {
return EXIT_FAILURE;
}
- initPaths();
+ initPaths(options.playlistDirArg,options.musicDirArg);
initPermissions();
- if(options.playlistDirArg[0]=='/') {
- strcpy(playlistDir,options.playlistDirArg);
- }
- else {
- getcwd(playlistDir,MAXPATHLEN-strlen(options.playlistDirArg)-1);
- if(playlistDir[strlen(playlistDir)-1]!='/') {
- strcat(playlistDir,"/");
- }
- strcat(playlistDir,options.playlistDirArg);
- }
- if(playlistDir[strlen(playlistDir)-1]!='/') {
- strcat(playlistDir,"/");
- }
- if((stat(playlistDir,&st))<0) {
- ERROR("problem stat'ing \"%s\"\n",options.playlistDirArg);
- return EXIT_FAILURE;
- }
- if(!S_ISDIR(st.st_mode)) {
- ERROR("\"%s\" is not a directory\n",options.playlistDirArg);
- return EXIT_FAILURE;
- }
-
- if(options.musicDirArg[0]=='/') {
- strcpy(musicDir,options.musicDirArg);
- }
- else {
- getcwd(musicDir,MAXPATHLEN-strlen(options.musicDirArg)-1);
- if(musicDir[strlen(musicDir)-1]!='/') strcat(musicDir,"/");
- strcat(musicDir,options.musicDirArg);
- }
- if(musicDir[strlen(musicDir)-1]!='/') strcat(musicDir,"/");
- if((stat(musicDir,&st))<0) {
- ERROR("problem stat'ing \"%s\"\n",options.musicDirArg);
- return EXIT_FAILURE;
- }
- if(!S_ISDIR(st.st_mode)) {
- ERROR("\"%s\" is not a directory\n",options.musicDirArg);
- return EXIT_FAILURE;
- }
-
initTables();
initPlaylist();
- if(!options.dbFile) {
- strncpy(directorydb,playlistDir,MAXPATHLEN);
- directorydb[MAXPATHLEN] = '\0';
- strncat(directorydb,"/.mpddb",MAXPATHLEN-strlen(playlistDir));
- }
- else {
- strncpy(directorydb,options.dbFile,MAXPATHLEN);
- directorydb[MAXPATHLEN] = '\0';
- }
+ if(!options.dbFile) directorydb = strdup(rpp2app(".mpddb"));
+ else directorydb = strdup(options.dbFile);
+
if(options.createDB>0 || options.onlyCreateDB || readDirectoryDB()<0)
{
if(options.createDB<0) {
diff --git a/src/path.c b/src/path.c
index 7226cbdec..6eecf084e 100644
--- a/src/path.c
+++ b/src/path.c
@@ -24,6 +24,9 @@
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO
@@ -32,8 +35,8 @@
#endif
#endif
-char musicDir[MAXPATHLEN+1];
-char playlistDir[MAXPATHLEN+1];
+char * musicDir;
+char * playlistDir;
char * fsCharset = NULL;
@@ -106,9 +109,30 @@ char * getFsCharset() {
return fsCharset;
}
-void initPaths() {
+void initPaths(char * playlistDirArg, char * musicDirArg) {
char * charset = NULL;
char * originalLocale;
+ struct stat st;
+
+ playlistDir = prependCwdToPathDup(playlistDirArg);
+ if((stat(playlistDir,&st))<0) {
+ ERROR("problem stat'ing \"%s\"\n",playlistDirArg);
+ exit(EXIT_FAILURE);
+ }
+ if(!S_ISDIR(st.st_mode)) {
+ ERROR("\"%s\" is not a directory\n",playlistDirArg);
+ exit(EXIT_FAILURE);
+ }
+
+ musicDir = prependCwdToPathDup(musicDirArg);
+ if((stat(musicDir,&st))<0) {
+ ERROR("problem stat'ing \"%s\"\n",musicDirArg);
+ exit(EXIT_FAILURE);
+ }
+ if(!S_ISDIR(st.st_mode)) {
+ ERROR("\"%s\" is not a directory\n",musicDirArg);
+ exit(EXIT_FAILURE);
+ }
if(getConf()[CONF_FS_CHARSET]) {
charset = strdup(getConf()[CONF_FS_CHARSET]);
@@ -241,4 +265,35 @@ char * sanitizePathDup(char * path) {
return realloc(ret,len+1);
}
+
+char * prependCwdToPathDup(char * path) {
+ int len = MAXPATHLEN+1;
+ char * ret = malloc(len);
+
+ memset(ret,0,len);
+
+ len = 0;
+
+ if(path[0]=='/') {
+ strncpy(ret,path,MAXPATHLEN);
+ len = strlen(ret);
+ }
+ else {
+ getcwd(ret,MAXPATHLEN);
+ len = strlen(ret);
+ if(ret[len-1]!='/') {
+ strncat(ret,"/",MAXPATHLEN-len);
+ len = strlen(path);
+ }
+ strncat(ret,path,MAXPATHLEN-len);
+ len = strlen(ret);
+ }
+ if(ret[len-1]!='/') {
+ strncat(ret,"/",MAXPATHLEN-len);
+ len = strlen(path);
+ }
+
+ return realloc(ret,len+1);
+}
+
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/path.h b/src/path.h
index d6b8bdae2..67234072a 100644
--- a/src/path.h
+++ b/src/path.h
@@ -23,10 +23,9 @@
#include <sys/param.h>
-extern char musicDir[MAXPATHLEN+1];
-extern char playlistDir[MAXPATHLEN+1];
+extern char * musicDir;
-void initPaths();
+void initPaths(char * playlistDirArg, char * musicDirArg);
void finishPaths();
@@ -52,5 +51,7 @@ char * parentPath(char * path);
/* strips extra "///" and leading "/" and trailing "/" */
char * sanitizePathDup(char * path);
+char * prependCwdToPathDup(char * path);
+
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/playlist.c b/src/playlist.c
index 1b01b4e4d..e7a5c8438 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -1053,8 +1053,8 @@ int savePlaylist(FILE * fp, char * utf8file) {
for(i=0;i<playlist.length;i++) {
if(playlist_saveAbsolutePaths) {
- myfprintf(fileP,"%s%s\n",musicDir,
- utf8ToFsCharset((playlist.songs[i])->utf8file));
+ myfprintf(fileP,"%s\n",rmp2amp(utf8ToFsCharset((
+ playlist.songs[i])->utf8file)));
}
else myfprintf(fileP,"%s\n",
utf8ToFsCharset((playlist.songs[i])->utf8file));