diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-05-29 17:46:40 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-05-29 21:23:43 +0200 |
commit | 29da419305e6cc3c660172e7edcd2f423dc1108b (patch) | |
tree | 08f635933b7dcc8da45367758909ea7270d8b7ac /src/basic/stat-util.c | |
parent | 8acb11a6a337601a6f307fb50d77b13ffa0b3c5e (diff) | |
download | systemd-29da419305e6cc3c660172e7edcd2f423dc1108b.tar.gz |
stat-util: trivial empty_or_null() tweaks
To small tweaks: /dev/null is definitely a char device. And if we have
the path, to a string base comparison first.
Diffstat (limited to 'src/basic/stat-util.c')
-rw-r--r-- | src/basic/stat-util.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index e4e4d8f076..904584a985 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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; |