From 6981203f3a824ac3ceeb5a23c66942d5a284d9bb Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 20 Jan 2025 21:15:46 +0100 Subject: [PATCH] fs-util: introduce at_flags_normalize_nofollow() helper --- src/basic/fs-util.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index 5ee7417eeb..eb031a0ccd 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -163,3 +163,12 @@ static inline int xopenat_lock(int dir_fd, const char *path, int open_flags, Loc int link_fd(int fd, int newdirfd, const char *newpath); int linkat_replace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); + +static inline int at_flags_normalize_nofollow(int flags) { + if (FLAGS_SET(flags, AT_SYMLINK_FOLLOW)) { + assert(!FLAGS_SET(flags, AT_SYMLINK_NOFOLLOW)); + flags &= ~AT_SYMLINK_FOLLOW; + } else + flags |= AT_SYMLINK_NOFOLLOW; + return flags; +}