aboutsummaryrefslogtreecommitdiffstats
path: root/src/output_state.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-07-15 16:57:37 +0200
committerMax Kellermann <max@duempel.org>2009-07-15 16:57:37 +0200
commitf7cc5b2efddece7cdc4fc5b7fc5324d33b7dfa8f (patch)
treec3b528d0972f857c1d80f0d26eff3491b6929777 /src/output_state.c
parentdf7d7732c61deec0102950cb3d79b9bd114e73a9 (diff)
downloadmpd-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 '')
-rw-r--r--src/output_state.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/output_state.c b/src/output_state.c
index c7e6c8579..5efae3626 100644
--- a/src/output_state.c
+++ b/src/output_state.c
@@ -49,35 +49,34 @@ saveAudioDevicesState(FILE *fp)
}
}
-void
-readAudioDevicesState(FILE *fp)
+bool
+readAudioDevicesState(const char *line)
{
- char buffer[1024];
-
- while (fgets(buffer, sizeof(buffer), fp)) {
- char *c, *name;
- struct audio_output *ao;
+ long value;
+ char *endptr;
+ const char *name;
+ struct audio_output *ao;
- g_strchomp(buffer);
+ if (!g_str_has_prefix(line, AUDIO_DEVICE_STATE))
+ return false;
- if (!g_str_has_prefix(buffer, AUDIO_DEVICE_STATE))
- continue;
+ line += sizeof(AUDIO_DEVICE_STATE) - 1;
- c = strchr(buffer, ':');
- if (!c || !(++c))
- goto errline;
+ value = strtol(line, &endptr, 10);
+ if (*endptr != ':' || (value != 0 && value != 1))
+ return false;
- name = strchr(c, ':');
- if (!name || !(++name))
- goto errline;
+ if (value != 0)
+ /* state is "enabled": no-op */
+ return true;
- ao = audio_output_find(name);
- if (ao != NULL && atoi(c) == 0)
- ao->enabled = false;
-
- continue;
-errline:
- /* nonfatal */
- g_warning("invalid line in state_file: %s\n", buffer);
+ name = endptr + 1;
+ ao = audio_output_find(name);
+ if (ao == NULL) {
+ g_debug("Ignoring device state for '%s'", name);
+ return true;
}
+
+ ao->enabled = false;
+ return true;
}