]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: add statx_verify_directory() helper, similar to stat_verify_directory...
authorLennart Poettering <lennart@amutable.com>
Thu, 5 Feb 2026 15:42:20 +0000 (16:42 +0100)
committerLennart Poettering <lennart@amutable.com>
Mon, 9 Feb 2026 09:33:01 +0000 (10:33 +0100)
src/basic/stat-util.c
src/basic/stat-util.h

index 9eaf17624a9e1a20b113fd484e73ab96c2acdaaa..d5df4acc2875b3570a527fb4096209039d5b5e9f 100644 (file)
@@ -90,6 +90,21 @@ int stat_verify_directory(const struct stat *st) {
         return 0;
 }
 
+int statx_verify_directory(const struct statx *stx) {
+        assert(stx);
+
+        if (!FLAGS_SET(stx->stx_mask, STATX_TYPE))
+                return -ENODATA;
+
+        if (S_ISLNK(stx->stx_mode))
+                return -ELOOP;
+
+        if (!S_ISDIR(stx->stx_mode))
+                return -ENOTDIR;
+
+        return 0;
+}
+
 int fd_verify_directory(int fd) {
         if (IN_SET(fd, AT_FDCWD, XAT_FDROOT))
                 return 0;
index 97dedd4b80b9f974f5fc8b1fab3abd95c07fb752..65af98e76a7249ed7a1765c6dbe64686f3add6a3 100644 (file)
@@ -11,6 +11,7 @@ int verify_regular_at(int fd, const char *path, bool follow);
 int fd_verify_regular(int fd);
 
 int stat_verify_directory(const struct stat *st);
+int statx_verify_directory(const struct statx *stx);
 int fd_verify_directory(int fd);
 int is_dir_at(int fd, const char *path, bool follow);
 int is_dir(const char *path, bool follow);