]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: trivial empty_or_null() tweaks
authorLennart Poettering <lennart@poettering.net>
Fri, 29 May 2020 15:46:40 +0000 (17:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 May 2020 19:23:43 +0000 (21:23 +0200)
To small tweaks: /dev/null is definitely a char device. And if we have
the path, to a string base comparison first.

src/basic/stat-util.c

index e4e4d8f0762108bedb3e8f863acb1d8887d33e7f..904584a9857c7fc7b875493ca932fabdc342a904 100644 (file)
@@ -94,10 +94,10 @@ bool null_or_empty(struct stat *st) {
         if (S_ISREG(st->st_mode) && st->st_size <= 0)
                 return true;
 
-        /* We don't want to hardcode the major/minor of /dev/null,
-         * hence we do a simpler "is this a device node?" check. */
+        /* We don't want to hardcode the major/minor of /dev/null, hence we do a simpler "is this a character
+         * device node?" check. */
 
-        if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
+        if (S_ISCHR(st->st_mode))
                 return true;
 
         return false;
@@ -108,6 +108,10 @@ int null_or_empty_path(const char *fn) {
 
         assert(fn);
 
+        /* If we have the path, let's do an easy text comparison first. */
+        if (path_equal(fn, "/dev/null"))
+                return true;
+
         if (stat(fn, &st) < 0)
                 return -errno;