aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-07 16:20:07 +0100
committerMax Kellermann <max@duempel.org>2009-11-07 16:20:07 +0100
commitc422344190836878e1229fdf85ca102d9fc40374 (patch)
treeec72d25c8adaa445794e1d740005ba630279fe58 /src
parent1a4cfc3d90b1ac3cc612d3f610caadb04179820c (diff)
downloadmpd-c422344190836878e1229fdf85ca102d9fc40374.tar.gz
mpd-c422344190836878e1229fdf85ca102d9fc40374.tar.xz
mpd-c422344190836878e1229fdf85ca102d9fc40374.zip
database: I/O error handling in db_save()
Check ferror() instead of the fprintf() return value.
Diffstat (limited to '')
-rw-r--r--src/database.c4
-rw-r--r--src/directory_save.c29
-rw-r--r--src/directory_save.h2
3 files changed, 16 insertions, 19 deletions
diff --git a/src/database.c b/src/database.c
index 70fce0c18..2164a69b7 100644
--- a/src/database.c
+++ b/src/database.c
@@ -251,7 +251,9 @@ db_save(void)
fprintf(fp, "%s\n", DIRECTORY_INFO_END);
- if (directory_save(fp, music_root) < 0) {
+ directory_save(fp, music_root);
+
+ if (ferror(fp)) {
g_warning("Failed to write to database file: %s",
strerror(errno));
while (fclose(fp) && errno == EINTR);
diff --git a/src/directory_save.c b/src/directory_save.c
index a22d28ffb..317f64bb4 100644
--- a/src/directory_save.c
+++ b/src/directory_save.c
@@ -39,43 +39,38 @@ directory_quark(void)
return g_quark_from_static_string("directory");
}
-/* TODO error checking */
-int
+void
directory_save(FILE *fp, struct directory *directory)
{
struct dirvec *children = &directory->children;
size_t i;
- int retv;
if (!directory_is_root(directory)) {
fprintf(fp, DIRECTORY_MTIME "%lu\n",
(unsigned long)directory->mtime);
- retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
- directory_get_path(directory));
- if (retv < 0)
- return -1;
+ fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
+ directory_get_path(directory));
}
for (i = 0; i < children->nr; ++i) {
struct directory *cur = children->base[i];
char *base = g_path_get_basename(cur->path);
- retv = fprintf(fp, DIRECTORY_DIR "%s\n", base);
+ fprintf(fp, DIRECTORY_DIR "%s\n", base);
g_free(base);
- if (retv < 0)
- return -1;
- if (directory_save(fp, cur) < 0)
- return -1;
+
+ directory_save(fp, cur);
+
+ if (ferror(fp))
+ return;
}
songvec_save(fp, &directory->songs);
- if (!directory_is_root(directory) &&
- fprintf(fp, DIRECTORY_END "%s\n",
- directory_get_path(directory)) < 0)
- return -1;
- return 0;
+ if (!directory_is_root(directory))
+ fprintf(fp, DIRECTORY_END "%s\n",
+ directory_get_path(directory));
}
static struct directory *
diff --git a/src/directory_save.h b/src/directory_save.h
index d9daa3fed..fa2775624 100644
--- a/src/directory_save.h
+++ b/src/directory_save.h
@@ -27,7 +27,7 @@
struct directory;
-int
+void
directory_save(FILE *fp, struct directory *directory);
bool