chiark / gitweb /
udev: remove seqnum API and all assumptions about seqnums
[elogind.git] / src / udev / udevadm-hwdb.c
index 1f7f0c72904349d25b161e83057b58c9f797cee5..65cbf618656a970ec447b2eed276625a77753c0c 100644 (file)
@@ -190,7 +190,7 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
                                 continue;
 
                         /* split node */
-                        new_child = calloc(sizeof(struct trie_node), 1);
+                        new_child = new0(struct trie_node, 1);
                         if (!new_child)
                                 return -ENOMEM;
 
@@ -233,7 +233,7 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
                         ssize_t off;
 
                         /* new child */
-                        child = calloc(sizeof(struct trie_node), 1);
+                        child = new0(struct trie_node, 1);
                         if (!child)
                                 return -ENOMEM;
 
@@ -341,7 +341,7 @@ static int trie_store(struct trie *trie, const char *filename) {
         struct trie_f t = {
                 .trie = trie,
         };
-        char *filename_tmp;
+        _cleanup_free_ char *filename_tmp = NULL;
         int64_t pos;
         int64_t root_off;
         int64_t size;
@@ -385,24 +385,23 @@ static int trie_store(struct trie *trie, const char *filename) {
                 err = -errno;
         fclose(t.f);
         if (err < 0 || rename(filename_tmp, filename) < 0) {
-                unlink(filename_tmp);
-                goto out;
+                unlink_noerrno(filename_tmp);
+                return err < 0 ? err : -errno;
         }
 
         log_debug("=== trie on-disk ===");
-        log_debug("size:             %8llu bytes", (unsigned long long)size);
+        log_debug("size:             %8"PRIu64" bytes", size);
         log_debug("header:           %8zu bytes", sizeof(struct trie_header_f));
-        log_debug("nodes:            %8llu bytes (%8llu)",
-                  (unsigned long long)t.nodes_count * sizeof(struct trie_node_f), (unsigned long long)t.nodes_count);
-        log_debug("child pointers:   %8llu bytes (%8llu)",
-                  (unsigned long long)t.children_count * sizeof(struct trie_child_entry_f), (unsigned long long)t.children_count);
-        log_debug("value pointers:   %8llu bytes (%8llu)",
-                  (unsigned long long)t.values_count * sizeof(struct trie_value_entry_f), (unsigned long long)t.values_count);
-        log_debug("string store:     %8llu bytes", (unsigned long long)trie->strings->len);
-        log_debug("strings start:    %8llu", (unsigned long long) t.strings_off);
-out:
-        free(filename_tmp);
-        return err;
+        log_debug("nodes:            %8"PRIu64" bytes (%8"PRIu64")",
+                  t.nodes_count * sizeof(struct trie_node_f), t.nodes_count);
+        log_debug("child pointers:   %8"PRIu64" bytes (%8"PRIu64")",
+                  t.children_count * sizeof(struct trie_child_entry_f), t.children_count);
+        log_debug("value pointers:   %8"PRIu64" bytes (%8"PRIu64")",
+                  t.values_count * sizeof(struct trie_value_entry_f), t.values_count);
+        log_debug("string store:     %8zu bytes", trie->strings->len);
+        log_debug("strings start:    %8"PRIu64, t.strings_off);
+
+        return 0;
 }
 
 static int insert_data(struct trie *trie, struct udev_list *match_list,
@@ -576,7 +575,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
                 char **files, **f;
                 _cleanup_free_ char *hwdb_bin = NULL;
 
-                trie = calloc(sizeof(struct trie), 1);
+                trie = new0(struct trie, 1);
                 if (!trie) {
                         rc = EXIT_FAILURE;
                         goto out;
@@ -590,7 +589,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
                 }
 
                 /* index */
-                trie->root = calloc(sizeof(struct trie_node), 1);
+                trie->root = new0(struct trie_node, 1);
                 if (!trie->root) {
                         rc = EXIT_FAILURE;
                         goto out;