aboutsummaryrefslogtreecommitdiff
path: root/src/audio.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-07-30 23:32:47 +0000
committerEric Wong <normalperson@yhbt.net>2006-07-30 23:32:47 +0000
commit12aec5738b8333a0dd676871bbfb6d6762ea87a5 (patch)
treeb2bb99e19e6a771f01bb465f38f4d878d6a9d805 /src/audio.c
parent381d7232a0d63c0a145fae5e2c40e577ff2f44f1 (diff)
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
Diffstat (limited to 'src/audio.c')
-rw-r--r--src/audio.c48
1 files changed, 5 insertions, 43 deletions
diff --git a/src/audio.c b/src/audio.c
index 8ecae5ec..b4f0dadc 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 <stdlib.h>
#include <string.h>
@@ -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);
-}