]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: group access_fd() with access_nofollow()
authorMike Yuan <me@yhndnzj.com>
Sun, 18 Jan 2026 22:04:39 +0000 (23:04 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 19 Jan 2026 12:33:27 +0000 (13:33 +0100)
src/basic/fs-util.c
src/basic/fs-util.h

index 4ca01c74440f89c83224116f55c7f637ab6b162b..0159934ddb39aaaabf36a9e82d0c60d96bd8bbb5 100644 (file)
@@ -360,6 +360,19 @@ int access_nofollow(const char *path, int mode) {
         return RET_NERRNO(faccessat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW));
 }
 
+int access_fd(int fd, int mode) {
+        /* Like access() but operates on an already open fd */
+
+        if (fd == AT_FDCWD)
+                return RET_NERRNO(access(".", mode));
+        if (fd == XAT_FDROOT)
+                return RET_NERRNO(access("/", mode));
+
+        assert(fd >= 0);
+
+        return RET_NERRNO(faccessat(fd, "", mode, AT_EMPTY_PATH));
+}
+
 int touch_fd(int fd, usec_t stamp) {
         assert(fd >= 0);
 
@@ -697,19 +710,6 @@ char* unlink_and_free(char *p) {
         return mfree(p);
 }
 
-int access_fd(int fd, int mode) {
-        /* Like access() but operates on an already open fd */
-
-        if (fd == AT_FDCWD)
-                return RET_NERRNO(access(".", mode));
-        if (fd == XAT_FDROOT)
-                return RET_NERRNO(access("/", mode));
-
-        assert(fd >= 0);
-
-        return RET_NERRNO(faccessat(fd, "", mode, AT_EMPTY_PATH));
-}
-
 int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
         _cleanup_close_ int truncate_fd = -EBADF;
         struct stat st;
index b26674d139f0ab4ba937a51ef1c1e4eecc561b72..d75c253dbb46aa7008bb974b4376a32f6fc4d850 100644 (file)
@@ -42,6 +42,7 @@ int fd_warn_permissions(const char *path, int fd);
 int stat_warn_permissions(const char *path, const struct stat *st);
 
 int access_nofollow(const char *path, int mode);
+int access_fd(int fd, int mode);
 
 int touch_fd(int fd, usec_t stamp);
 int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
@@ -86,8 +87,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rmdir_and_free);
 char* unlink_and_free(char *p);
 DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free);
 
-int access_fd(int fd, int mode);
-
 typedef enum UnlinkDeallocateFlags {
         UNLINK_REMOVEDIR = 1 << 0,
         UNLINK_ERASE     = 1 << 1,