]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-hwdb/hwdb-util.c
util-lib: split out all temporary file related calls into tmpfiles-util.c
[thirdparty/systemd.git] / src / libsystemd / sd-hwdb / hwdb-util.c
index fe1f93baeb429bccf0e51310da2821f6ac9945df..c5c329f2ac6c7538172a7541059188cff40b70db 100644 (file)
@@ -16,6 +16,7 @@
 #include "strbuf.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tmpfile-util.h"
 
 static const char *default_hwdb_bin_dir = "/etc/udev";
 static const char * const conf_file_dirs[] = {
@@ -133,7 +134,7 @@ static int trie_values_cmp(const struct trie_value_entry *a, const struct trie_v
 static int trie_node_add_value(struct trie *trie, struct trie_node *node,
                                const char *key, const char *value,
                                const char *filename, uint16_t file_priority, uint32_t line_number, bool compat) {
-        ssize_t k, v, fn;
+        ssize_t k, v, fn = 0;
         struct trie_value_entry *val;
 
         k = strbuf_add_string(trie->strings, key, strlen(key));
@@ -472,7 +473,6 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
                 HW_DATA,
         } state = HW_NONE;
         _cleanup_fclose_ FILE *f = NULL;
-        char line[LINE_MAX];
         _cleanup_strv_free_ char **match_list = NULL;
         uint32_t line_number = 0;
         char *match = NULL;
@@ -482,10 +482,17 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
         if (!f)
                 return -errno;
 
-        while (fgets(line, sizeof(line), f)) {
+        for (;;) {
+                _cleanup_free_ char *line = NULL;
                 size_t len;
                 char *pos;
 
+                r = read_line(f, LONG_LINE_MAX, &line);
+                if (r < 0)
+                        return r;
+                if (r == 0)
+                        break;
+
                 ++line_number;
 
                 /* comment line */