diff options
author | Max Kellermann <max@duempel.org> | 2009-11-07 16:20:07 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-11-07 16:20:07 +0100 |
commit | c422344190836878e1229fdf85ca102d9fc40374 (patch) | |
tree | ec72d25c8adaa445794e1d740005ba630279fe58 /src/directory_save.c | |
parent | 1a4cfc3d90b1ac3cc612d3f610caadb04179820c (diff) |
database: I/O error handling in db_save()
Check ferror() instead of the fprintf() return value.
Diffstat (limited to 'src/directory_save.c')
-rw-r--r-- | src/directory_save.c | 29 |
1 files changed, 12 insertions, 17 deletions
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 * |