]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use null_or_empty_path()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Mar 2021 08:25:22 +0000 (17:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Mar 2021 23:09:05 +0000 (08:09 +0900)
This also drops unnecessary fseek().

src/network/netdev/netdev.c
src/network/networkd-network.c

index fb0353486932596363ae00d4ed3ae6f72ba02275..b31f0fa81ab23f7c77fc604a28e37edd28c29635 100644 (file)
@@ -656,7 +656,6 @@ int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t callb
 
 int netdev_load_one(Manager *manager, const char *filename) {
         _cleanup_(netdev_unrefp) NetDev *netdev_raw = NULL, *netdev = NULL;
-        _cleanup_fclose_ FILE *file = NULL;
         const char *dropin_dirname;
         bool independent = false;
         int r;
@@ -664,15 +663,12 @@ int netdev_load_one(Manager *manager, const char *filename) {
         assert(manager);
         assert(filename);
 
-        file = fopen(filename, "re");
-        if (!file) {
-                if (errno == ENOENT)
-                        return 0;
-
-                return -errno;
-        }
-
-        if (null_or_empty_fd(fileno(file))) {
+        r = null_or_empty_path(filename);
+        if (r == -ENOENT)
+                return 0;
+        if (r < 0)
+                return r;
+        if (r > 0) {
                 log_debug("Skipping empty file: %s", filename);
                 return 0;
         }
@@ -714,10 +710,6 @@ int netdev_load_one(Manager *manager, const char *filename) {
                 return 0;
         }
 
-        r = fseek(file, 0, SEEK_SET);
-        if (r < 0)
-                return -errno;
-
         netdev = malloc0(NETDEV_VTABLE(netdev_raw)->object_size);
         if (!netdev)
                 return log_oom();
index 9865ebd2552a2ac5e738cfd1314eb2d9a211c31f..e5ffd35b6f9ab4b6a785678acec3622d60357ddd 100644 (file)
@@ -288,7 +288,6 @@ int network_verify(Network *network) {
 int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename) {
         _cleanup_free_ char *fname = NULL, *name = NULL;
         _cleanup_(network_unrefp) Network *network = NULL;
-        _cleanup_fclose_ FILE *file = NULL;
         const char *dropin_dirname;
         char *d;
         int r;
@@ -296,15 +295,12 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
         assert(manager);
         assert(filename);
 
-        file = fopen(filename, "re");
-        if (!file) {
-                if (errno == ENOENT)
-                        return 0;
-
-                return -errno;
-        }
-
-        if (null_or_empty_fd(fileno(file))) {
+        r = null_or_empty_path(filename);
+        if (r == -ENOENT)
+                return 0;
+        if (r < 0)
+                return r;
+        if (r > 0) {
                 log_debug("Skipping empty file: %s", filename);
                 return 0;
         }