]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-hwdb/sd-hwdb.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / libsystemd / sd-hwdb / sd-hwdb.c
index 2a0e00f7d234a5b5b10f37c2735964df5dd56124..4932c191993cfedadb2f418987c3f9fb36df8e28 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
+#include <fnmatch.h>
 #include <inttypes.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <fnmatch.h>
+#include <string.h>
 #include <sys/mman.h>
 
 #include "sd-hwdb.h"
 
 #include "hashmap.h"
-#include "refcnt.h"
-
-#include "hwdb-util.h"
 #include "hwdb-internal.h"
+#include "hwdb-util.h"
+#include "refcnt.h"
+#include "string-util.h"
 
 struct sd_hwdb {
         RefCount n_ref;
@@ -79,8 +79,7 @@ static bool linebuf_add(struct linebuf *buf, const char *s, size_t len) {
         return true;
 }
 
-static bool linebuf_add_char(struct linebuf *buf, char c)
-{
+static bool linebuf_add_char(struct linebuf *buf, char c) {
         if (buf->len + 1 >= sizeof(buf->bytes))
                 return false;
         buf->bytes[buf->len++] = c;
@@ -269,13 +268,13 @@ static int trie_search_f(sd_hwdb *hwdb, const char *search) {
 }
 
 static const char hwdb_bin_paths[] =
-    "/etc/systemd/hwdb/hwdb.bin\0"
-    "/etc/udev/hwdb.bin\0"
-    "/usr/lib/systemd/hwdb/hwdb.bin\0"
+        "/etc/systemd/hwdb/hwdb.bin\0"
+        "/etc/udev/hwdb.bin\0"
+        "/usr/lib/systemd/hwdb/hwdb.bin\0"
 #ifdef HAVE_SPLIT_USR
-    "/lib/systemd/hwdb/hwdb.bin\0"
+        "/lib/systemd/hwdb/hwdb.bin\0"
 #endif
-    UDEVLIBEXECDIR "/hwdb.bin\0";
+        UDEVLIBEXECDIR "/hwdb.bin\0";
 
 _public_ int sd_hwdb_new(sd_hwdb **ret) {
         _cleanup_hwdb_unref_ sd_hwdb *hwdb = NULL;
@@ -345,8 +344,7 @@ _public_ sd_hwdb *sd_hwdb_unref(sd_hwdb *hwdb) {
         if (hwdb && REFCNT_DEC(hwdb->n_ref) == 0) {
                 if (hwdb->map)
                         munmap((void *)hwdb->map, hwdb->st.st_size);
-                if (hwdb->f)
-                        fclose(hwdb->f);
+                safe_fclose(hwdb->f);
                 free(hwdb->modalias);
                 ordered_hashmap_free(hwdb->properties);
                 free(hwdb);
@@ -449,7 +447,8 @@ _public_ int sd_hwdb_seek(sd_hwdb *hwdb, const char *modalias) {
 }
 
 _public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **value) {
-        const void *k, *v;
+        const void *k;
+        void *v;
 
         assert_return(hwdb, -EINVAL);
         assert_return(key, -EINVAL);
@@ -458,7 +457,7 @@ _public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **val
         if (hwdb->properties_modified)
                 return -EAGAIN;
 
-        v = ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &k);
+        ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &v, &k);
         if (!k)
                 return 0;