]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: split null_or_empty() into two
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 26 Jun 2025 13:49:31 +0000 (22:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 27 Jun 2025 18:54:48 +0000 (03:54 +0900)
src/basic/stat-util.c
src/basic/stat-util.h

index cbdcf190547a0c376b3714e1ff31a4658d9746e1..94b4f55c3492b757ed020bc3e7c3122083a27982 100644 (file)
@@ -184,19 +184,19 @@ int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup)
         return 1;
 }
 
-bool null_or_empty(struct stat *st) {
+bool stat_may_be_dev_null(struct stat *st) {
         assert(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 character
          * device node?" check. */
 
-        if (S_ISCHR(st->st_mode))
-                return true;
+        return S_ISCHR(st->st_mode);
+}
 
-        return false;
+bool stat_is_empty(struct stat *st) {
+        assert(st);
+
+        return S_ISREG(st->st_mode) && st->st_size <= 0;
 }
 
 int null_or_empty_path_with_root(const char *fn, const char *root) {
index 11da6f4ab7a7713f744e734deb96d930d821c886..347d885a19fbed29fefa6f84af9977afbbe54faf 100644 (file)
@@ -29,7 +29,11 @@ static inline int dir_is_empty(const char *path, bool ignore_hidden_or_backup) {
         return dir_is_empty_at(AT_FDCWD, path, ignore_hidden_or_backup);
 }
 
-bool null_or_empty(struct stat *st) _pure_;
+bool stat_may_be_dev_null(struct stat *st) _pure_;
+bool stat_is_empty(struct stat *st) _pure_;
+static inline bool null_or_empty(struct stat *st) {
+        return stat_may_be_dev_null(st) || stat_is_empty(st);
+}
 int null_or_empty_path_with_root(const char *fn, const char *root);
 
 static inline int null_or_empty_path(const char *fn) {