aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2005-03-06 20:04:50 +0000
committerWarren Dukes <warren.dukes@gmail.com>2005-03-06 20:04:50 +0000
commit32a1f952e85d5c8f2f2c19dffecc05b4ee8364b2 (patch)
treea4218fc0e38db99bed5cfe9108d4a4c2fcdb8e93 /src/playlist.c
parent522bb6b61fcad9e752f45bf689755cc265e6502c (diff)
downloadmpd-32a1f952e85d5c8f2f2c19dffecc05b4ee8364b2.tar.gz
mpd-32a1f952e85d5c8f2f2c19dffecc05b4ee8364b2.tar.xz
mpd-32a1f952e85d5c8f2f2c19dffecc05b4ee8364b2.zip
fix stateFile path getting garbled
git-svn-id: https://svn.musicpd.org/mpd/trunk@3029 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/playlist.c')
-rw-r--r--src/playlist.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/playlist.c b/src/playlist.c
index d7a946e25..3a2bfcc78 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -88,12 +88,18 @@ static int playlist_noGoToNext = 0;
static int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
-static char * playlist_stateFile = NULL;
-
static void swapOrder(int a, int b);
static int playPlaylistOrderNumber(FILE * fp, int orderNum);
static void randomizeOrder(int start, int end);
+static char * getStateFile() {
+ ConfigParam * param = parseConfigFilePath(CONF_STATE_FILE, 0);
+
+ if(!param) return NULL;
+
+ return param->value;
+}
+
static void incrPlaylistVersion() {
static unsigned long max = ((mpd_uint32)1<<31)-1;
playlist.version++;
@@ -179,8 +185,6 @@ void initPlaylist() {
srandom(time(NULL));
- playlist_stateFile = parseConfigFilePath(CONF_STATE_FILE, 0);
-
for(i=0; i<playlist_max_length*PLAYLIST_HASH_MULT; i++) {
playlist.idToPosition[i] = -1;
}
@@ -252,13 +256,15 @@ int showPlaylist(FILE * fp) {
}
void savePlaylistState() {
- if(playlist_stateFile) {
+ char * stateFile = getStateFile();
+
+ if(stateFile) {
FILE * fp;
- while(!(fp = fopen(playlist_stateFile,"w")) && errno==EINTR);
+ while(!(fp = fopen(stateFile,"w")) && errno==EINTR);
if(!fp) {
ERROR("problems opening state file \"%s\" for "
- "writing: %s\n", playlist_stateFile,
+ "writing: %s\n", stateFile,
strerror(errno));
return;
}
@@ -303,16 +309,16 @@ void loadPlaylistFromStateFile(FILE * fp, char * buffer, int state, int current,
{
char * temp;
int song;
+ char * stateFile = getStateFile();
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
- ERROR("error parsing state file \"%s\"\n",playlist_stateFile);
+ ERROR("error parsing state file \"%s\"\n", stateFile);
exit(EXIT_FAILURE);
}
while(strcmp(buffer,PLAYLIST_STATE_FILE_PLAYLIST_END)) {
song = atoi(strtok(buffer,":"));
if(!(temp = strtok(NULL,""))) {
- ERROR("error parsing state file \"%s\"\n",
- playlist_stateFile);
+ ERROR("error parsing state file \"%s\"\n", stateFile);
exit(EXIT_FAILURE);
}
if(addToPlaylist(stderr, temp, 0)==0 && current==song) {
@@ -328,15 +334,16 @@ void loadPlaylistFromStateFile(FILE * fp, char * buffer, int state, int current,
}
}
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
- ERROR("error parsing state file \"%s\"\n",
- playlist_stateFile);
+ ERROR("error parsing state file \"%s\"\n", stateFile);
exit(EXIT_FAILURE);
}
}
}
void readPlaylistState() {
- if(playlist_stateFile) {
+ char * stateFile = getStateFile();
+
+ if(stateFile) {
FILE * fp;
struct stat st;
int current = -1;
@@ -344,17 +351,20 @@ void readPlaylistState() {
int state = PLAYER_STATE_STOP;
char buffer[PLAYLIST_BUFFER_SIZE];
- if(stat(playlist_stateFile,&st)<0) return;
+ if(stat(stateFile,&st)<0) {
+ DEBUG("failed to stat state file\n");
+ return;
+ }
if(!S_ISREG(st.st_mode)) {
ERROR("state file \"%s\" is not a regular "
- "file\n",playlist_stateFile);
+ "file\n",stateFile);
exit(EXIT_FAILURE);
}
- fp = fopen(playlist_stateFile,"r");
+ fp = fopen(stateFile,"r");
if(!fp) {
ERROR("problems opening state file \"%s\" for "
- "reading: %s\n", playlist_stateFile,
+ "reading: %s\n", stateFile,
strerror(errno));
exit(EXIT_FAILURE);
}
@@ -407,7 +417,7 @@ void readPlaylistState() {
strlen(PLAYLIST_STATE_FILE_CURRENT)) {
ERROR("error parsing state "
"file \"%s\"\n",
- playlist_stateFile);
+ stateFile);
exit(EXIT_FAILURE);
}
current = atoi(&(buffer