diff options
author | Max Kellermann <max@duempel.org> | 2009-07-15 16:57:37 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-07-15 16:57:37 +0200 |
commit | f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f (patch) | |
tree | c3b528d0972f857c1d80f0d26eff3491b6929777 /src/state_file.c | |
parent | df7d7732c61deec0102950cb3d79b9bd114e73a9 (diff) | |
download | mpd-f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f.tar.gz mpd-f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f.tar.xz mpd-f7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f.zip |
state_file: don't rewind the stream while reading the state file
Parse the state file line by line, let each subsystem probe a line.
Only the playlist_state code gets the FILE pointer to read the
following lines.
Diffstat (limited to 'src/state_file.c')
-rw-r--r-- | src/state_file.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/state_file.c b/src/state_file.c index 3791c057d..18548d03c 100644 --- a/src/state_file.c +++ b/src/state_file.c @@ -63,6 +63,8 @@ static void state_file_read(void) { FILE *fp; + char line[1024]; + bool success; assert(state_file_path != NULL); @@ -75,11 +77,15 @@ state_file_read(void) return; } - read_sw_volume_state(fp); - rewind(fp); - readAudioDevicesState(fp); - rewind(fp); - playlist_state_restore(fp, &g_playlist); + while (fgets(line, sizeof(line), fp) != NULL) { + g_strchomp(line); + + success = read_sw_volume_state(line) || + readAudioDevicesState(line) || + playlist_state_restore(line, fp, &g_playlist); + if (!success) + g_warning("Unrecognized line in state file: %s", line); + } while(fclose(fp) && errno == EINTR) /* nothing */; } |