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/volume.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/volume.c')
-rw-r--r-- | src/volume.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/volume.c b/src/volume.c index 3e6079cd6..5f4a66837 100644 --- a/src/volume.c +++ b/src/volume.c @@ -100,24 +100,22 @@ bool volume_level_change(unsigned volume) return hardware_volume_change(volume); } -void read_sw_volume_state(FILE *fp) +bool +read_sw_volume_state(const char *line) { - char buf[sizeof(SW_VOLUME_STATE) + sizeof("100") - 1]; char *end = NULL; long int sv; - while (fgets(buf, sizeof(buf), fp)) { - if (!g_str_has_prefix(buf, SW_VOLUME_STATE)) - continue; - - g_strchomp(buf); - sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10); - if (G_LIKELY(!*end) && sv >= 0 && sv <= 100) - software_volume_change(sv); - else - g_warning("Can't parse software volume: %s\n", buf); - return; - } + if (!g_str_has_prefix(line, SW_VOLUME_STATE)) + return false; + + line += sizeof(SW_VOLUME_STATE) - 1; + sv = strtol(line, &end, 10); + if (*end == 0 && sv >= 0 && sv <= 100) + software_volume_change(sv); + else + g_warning("Can't parse software volume: %s\n", line); + return true; } void save_sw_volume_state(FILE *fp) |