stat-util: add stat_verify_socket() helper

This commit is contained in:
Lennart Poettering
2026-02-09 10:44:47 +01:00
parent 382f141fea
commit c0ee33f48f
2 changed files with 17 additions and 0 deletions
+15
View 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);
+2
View 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);