summaryrefslogtreecommitdiff
path: root/src/hwdb/hwdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hwdb/hwdb.c')
-rw-r--r--src/hwdb/hwdb.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index 41f74ad133..fba0c309c5 100644
--- a/src/hwdb/hwdb.c
+++ b/src/hwdb/hwdb.c
@@ -396,24 +396,21 @@ static int trie_store(struct trie *trie, const char *filename) {
.child_entry_size = htole64(sizeof(struct trie_child_entry_f)),
.value_entry_size = htole64(sizeof(struct trie_value_entry2_f)),
};
- int err;
+ int r;
/* calculate size of header, nodes, children entries, value entries */
t.strings_off = sizeof(struct trie_header_f);
trie_store_nodes_size(&t, trie->root);
- err = fopen_temporary(filename , &t.f, &filename_tmp);
- if (err < 0)
- return err;
+ r = fopen_temporary(filename , &t.f, &filename_tmp);
+ if (r < 0)
+ return r;
fchmod(fileno(t.f), 0444);
/* write nodes */
- err = fseeko(t.f, sizeof(struct trie_header_f), SEEK_SET);
- if (err < 0) {
- fclose(t.f);
- unlink_noerrno(filename_tmp);
- return -errno;
- }
+ if (fseeko(t.f, sizeof(struct trie_header_f), SEEK_SET) < 0)
+ goto error;
+
root_off = trie_store_nodes(&t, trie->root);
h.nodes_root_off = htole64(root_off);
pos = ftello(t.f);
@@ -426,20 +423,13 @@ static int trie_store(struct trie *trie, const char *filename) {
/* write header */
size = ftello(t.f);
h.file_size = htole64(size);
- err = fseeko(t.f, 0, SEEK_SET);
- if (err < 0) {
- fclose(t.f);
- unlink_noerrno(filename_tmp);
- return -errno;
- }
+ if (fseeko(t.f, 0, SEEK_SET) < 0)
+ goto error;
+
fwrite(&h, sizeof(struct trie_header_f), 1, t.f);
- err = ferror(t.f);
- if (err)
- err = -errno;
- fclose(t.f);
- if (err < 0 || rename(filename_tmp, filename) < 0) {
+ if (fclose(t.f) < 0 || rename(filename_tmp, filename) < 0) {
unlink_noerrno(filename_tmp);
- return err < 0 ? err : -errno;
+ return -errno;
}
log_debug("=== trie on-disk ===");
@@ -453,8 +443,13 @@ static int trie_store(struct trie *trie, const char *filename) {
t.values_count * sizeof(struct trie_value_entry2_f), t.values_count);
log_debug("string store: %8zu bytes", trie->strings->len);
log_debug("strings start: %8"PRIu64, t.strings_off);
-
return 0;
+
+ error:
+ r = -errno;
+ fclose(t.f);
+ unlink(filename_tmp);
+ return r;
}
static int insert_data(struct trie *trie, char **match_list, char *line,