summaryrefslogtreecommitdiffstats
path: root/src/basic/stat-util.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-25 02:54:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-25 02:54:54 +0000
commitaf2a7ac568af7b8ecf1002023dd9d07135c3c9c2 (patch)
tree581ab49f856374f88fabfc43ba54969edbe67316 /src/basic/stat-util.c
parentReleasing progress-linux version 255.4-1~progress7.99u1. (diff)
downloadsystemd-af2a7ac568af7b8ecf1002023dd9d07135c3c9c2.tar.xz
systemd-af2a7ac568af7b8ecf1002023dd9d07135c3c9c2.zip
Merging upstream version 255.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/basic/stat-util.c')
-rw-r--r--src/basic/stat-util.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c
index c54374b..581370d 100644
--- a/src/basic/stat-util.c
+++ b/src/basic/stat-util.c
@@ -262,11 +262,31 @@ int path_is_network_fs(const char *path) {
return is_network_fs(&s);
}
+int stat_verify_linked(const struct stat *st) {
+ assert(st);
+
+ if (st->st_nlink <= 0)
+ return -EIDRM; /* recognizable error. */
+
+ return 0;
+}
+
+int fd_verify_linked(int fd) {
+ struct stat st;
+
+ assert(fd >= 0);
+
+ if (fstat(fd, &st) < 0)
+ return -errno;
+
+ return stat_verify_linked(&st);
+}
+
int stat_verify_regular(const struct stat *st) {
assert(st);
- /* Checks whether the specified stat() structure refers to a regular file. If not returns an appropriate error
- * code. */
+ /* Checks whether the specified stat() structure refers to a regular file. If not returns an
+ * appropriate error code. */
if (S_ISDIR(st->st_mode))
return -EISDIR;
@@ -470,7 +490,7 @@ int xstatfsat(int dir_fd, const char *path, struct statfs *ret) {
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
assert(ret);
- fd = xopenat(dir_fd, path, O_PATH|O_CLOEXEC|O_NOCTTY, /* xopen_flags = */ 0, /* mode = */ 0);
+ fd = xopenat(dir_fd, path, O_PATH|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return fd;