aboutsummaryrefslogtreecommitdiffstats
path: root/src/state_file.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-18 04:29:53 -0700
committerEric Wong <normalperson@yhbt.net>2008-09-18 04:29:53 -0700
commit71ac281579c8b8b384cfc09d8627b549b1854fcd (patch)
treeb501975bac64ac2cb1be1e30860302ccb3eda67e /src/state_file.c
parentba4f62f7d241e2837111102a4dda0c917d544c99 (diff)
downloadmpd-71ac281579c8b8b384cfc09d8627b549b1854fcd.tar.gz
mpd-71ac281579c8b8b384cfc09d8627b549b1854fcd.tar.xz
mpd-71ac281579c8b8b384cfc09d8627b549b1854fcd.zip
Move away from fprintf() when writing DB/state_file
I have serious trust issues when using stdio to write to the FS. So it's best to clean this code out so I can start figuring out what's wrong with Rasi's box not updating... None of these writes take place in a performance-critical setting anyways...
Diffstat (limited to 'src/state_file.c')
-rw-r--r--src/state_file.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/state_file.c b/src/state_file.c
index 3bc4f8f0c..b7f28e538 100644
--- a/src/state_file.c
+++ b/src/state_file.c
@@ -29,7 +29,7 @@
static struct _sf_cb {
void (*reader)(FILE *);
- void (*writer)(FILE *);
+ void (*writer)(int);
} sf_callbacks [] = {
{ read_sw_volume_state, save_sw_volume_state },
{ readAudioDevicesState, saveAudioDevicesState },
@@ -51,22 +51,22 @@ static void get_state_file_path(void)
void write_state_file(void)
{
unsigned int i;
- FILE *fp;
+ int fd;
if (!sfpath)
return;
- while (!(fp = fopen(sfpath, "w")) && errno == EINTR);
-
- if (mpd_unlikely(!fp)) {
+ while (((fd = open(sfpath, O_WRONLY|O_TRUNC|O_CREAT)) < 0) &&
+ errno == EINTR);
+ if (fd < 0) {
ERROR("problems opening state file \"%s\" for writing: %s\n",
sfpath, strerror(errno));
return;
}
for (i = 0; i < ARRAY_SIZE(sf_callbacks); i++)
- sf_callbacks[i].writer(fp);
+ sf_callbacks[i].writer(fd);
- while(fclose(fp) && errno == EINTR) /* nothing */;
+ xclose(fd);
}
void read_state_file(void)