From 12aec5738b8333a0dd676871bbfb6d6762ea87a5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 30 Jul 2006 23:32:47 +0000 Subject: Standardize state_file handling routines. This way it's easier to manage and extend. git-svn-id: https://svn.musicpd.org/mpd/trunk@4494 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audio.c | 48 +++++------------------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c index 8ecae5ec3..b4f0dadc3 100644 --- a/src/audio.c +++ b/src/audio.c @@ -25,6 +25,7 @@ #include "playerData.h" #include "utils.h" #include "playlist.h" +#include "state_file.h" #include #include @@ -462,32 +463,19 @@ void printAudioDevices(int fd) } } -void saveAudioDevicesState(void) +void saveAudioDevicesState(FILE *fp) { - char *stateFile; - FILE *fp; int i; - if (!(stateFile = getStateFile())) - return; - - while (!(fp = fopen(stateFile, "a")) && errno == EINTR) ; - if (!fp) { - ERROR("problems opening state file \"%s\" for " - "writing: %s\n", stateFile, strerror(errno)); - return; - } - assert(audioOutputArraySize != 0); for (i = 0; i < audioOutputArraySize; i++) { fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n", - (int)pdAudioDevicesEnabled[i], - audioOutputArray[i]->name); + (int)pdAudioDevicesEnabled[i], + audioOutputArray[i]->name); } - while (fclose(fp) && errno == EINTR) ; } -static void parse_audio_device_state(FILE * fp) +void readAudioDevicesState(FILE *fp) { char buffer[AUDIO_BUFFER_SIZE]; int i; @@ -521,29 +509,3 @@ static void parse_audio_device_state(FILE * fp) } } -void readAudioDevicesState(void) -{ - char *stateFile; - FILE *fp; - struct stat st; - - if (!(stateFile = getStateFile())) - 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", stateFile); - exit(EXIT_FAILURE); - } - - fp = fopen(stateFile, "r"); - if (!fp) { - ERROR("problems opening state file \"%s\" for " - "reading: %s\n", stateFile, strerror(errno)); - exit(EXIT_FAILURE); - } - parse_audio_device_state(fp); - fclose(fp); -} -- cgit v1.2.3