]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: add stat_verify_socket() helper
authorLennart Poettering <lennart@amutable.com>
Fri, 6 Feb 2026 14:02:45 +0000 (15:02 +0100)
committerLennart Poettering <lennart@amutable.com>
Mon, 9 Feb 2026 09:44:47 +0000 (10:44 +0100)
src/basic/stat-util.c
src/basic/stat-util.h

index d5df4acc2875b3570a527fb4096209039d5b5e9f..f50b64e48465e5670f7fe4f578c0f50121e2d200 100644 (file)
@@ -142,6 +142,21 @@ int is_symlink(const char *path) {
         return verify_stat_at(AT_FDCWD, path, false, stat_verify_symlink, false);
 }
 
+int stat_verify_socket(const struct stat *st) {
+        assert(st);
+
+        if (S_ISLNK(st->st_mode))
+                return -ELOOP;
+
+        if (S_ISDIR(st->st_mode))
+                return -EISDIR;
+
+        if (!S_ISSOCK(st->st_mode))
+                return -ENOTSOCK;
+
+        return 0;
+}
+
 int stat_verify_linked(const struct stat *st) {
         assert(st);
 
index 65af98e76a7249ed7a1765c6dbe64686f3add6a3..e4138e960a3bfc867ec59db264729076ba3a5125 100644 (file)
@@ -20,6 +20,8 @@ int stat_verify_symlink(const struct stat *st);
 int fd_verify_symlink(int fd);
 int is_symlink(const char *path);
 
+int stat_verify_socket(const struct stat *st);
+
 int stat_verify_linked(const struct stat *st);
 int fd_verify_linked(int fd);