]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/stat-util: use xopenat() where appropriate
authorMike Yuan <me@yhndnzj.com>
Fri, 11 Oct 2024 16:04:17 +0000 (18:04 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 14 Oct 2024 23:16:57 +0000 (01:16 +0200)
src/basic/stat-util.c

index f05e66d80d0d7b5d16e32233272521df6ad276dd..2181ee2df51dcefc2b54f4cb3b986a48d899d007 100644 (file)
@@ -157,25 +157,9 @@ int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup)
         struct dirent *buf;
         size_t m;
 
-        if (path) {
-                assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
-
-                fd = openat(dir_fd, path, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
-                if (fd < 0)
-                        return -errno;
-        } else if (dir_fd == AT_FDCWD) {
-                fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
-                if (fd < 0)
-                        return -errno;
-        } else {
-                /* Note that DUPing is not enough, as the internal pointer would still be shared and moved
-                 * getedents64(). */
-                assert(dir_fd >= 0);
-
-                fd = fd_reopen(dir_fd, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
-                if (fd < 0)
-                        return fd;
-        }
+        fd = xopenat(dir_fd, path, O_DIRECTORY|O_CLOEXEC);
+        if (fd < 0)
+                return fd;
 
         /* Allocate space for at least 3 full dirents, since every dir has at least two entries ("."  +
          * ".."), and only once we have seen if there's a third we know whether the dir is empty or not. If