Add macro for checking if some flags are set
This way we don't need to repeat the argument twice. I didn't replace all instances. I think it's better to leave out: - asserts - comparisons like x & y == x, which are mathematically equivalent, but here we aren't checking if flags are set, but if the argument fits in the flags.
This commit is contained in:
@@ -41,7 +41,7 @@ static inline void cap_free_charpp(char **p) {
|
||||
static inline bool cap_test_all(uint64_t caps) {
|
||||
uint64_t m;
|
||||
m = (UINT64_C(1) << (cap_last_cap() + 1)) - 1;
|
||||
return (caps & m) == m;
|
||||
return FLAGS_SET(caps, m);
|
||||
}
|
||||
|
||||
bool ambient_capabilities_supported(void);
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ static int fd_is_nonblock_pipe(int fd) {
|
||||
if (flags < 0)
|
||||
return -errno;
|
||||
|
||||
return (flags & O_NONBLOCK) == O_NONBLOCK ? FD_IS_NONBLOCKING_PIPE : FD_IS_BLOCKING_PIPE;
|
||||
return FLAGS_SET(flags, O_NONBLOCK) ? FD_IS_NONBLOCKING_PIPE : FD_IS_BLOCKING_PIPE;
|
||||
}
|
||||
|
||||
int copy_bytes_full(
|
||||
|
||||
+2
-2
@@ -602,10 +602,10 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
||||
assert(path);
|
||||
|
||||
/* Either the file may be missing, or we return an fd to the final object, but both make no sense */
|
||||
if ((flags & (CHASE_NONEXISTENT|CHASE_OPEN)) == (CHASE_NONEXISTENT|CHASE_OPEN))
|
||||
if (FLAGS_SET(flags, CHASE_NONEXISTENT | CHASE_OPEN))
|
||||
return -EINVAL;
|
||||
|
||||
if ((flags & (CHASE_STEP|CHASE_OPEN)) == (CHASE_STEP|CHASE_OPEN))
|
||||
if (FLAGS_SET(flags, CHASE_STEP | CHASE_OPEN))
|
||||
return -EINVAL;
|
||||
|
||||
if (isempty(path))
|
||||
|
||||
@@ -357,6 +357,8 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
|
||||
|
||||
#define SET_FLAG(v, flag, b) \
|
||||
(v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
|
||||
#define FLAGS_SET(v, flags) \
|
||||
(((v) & (flags)) == (flags))
|
||||
|
||||
#define CASE_F(X) case X:
|
||||
#define CASE_F_1(CASE, X) CASE_F(X)
|
||||
|
||||
@@ -1359,7 +1359,7 @@ int safe_fork_full(
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & (FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE)) == (FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE)) {
|
||||
if (FLAGS_SET(flags, FORK_NEW_MOUNTNS | FORK_MOUNTNS_SLAVE)) {
|
||||
|
||||
/* Optionally, make sure we never propagate mounts to the host. */
|
||||
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if ((flags & (REMOVE_SUBVOLUME|REMOVE_ROOT|REMOVE_PHYSICAL)) == (REMOVE_SUBVOLUME|REMOVE_ROOT|REMOVE_PHYSICAL)) {
|
||||
if (FLAGS_SET(flags, REMOVE_SUBVOLUME | REMOVE_ROOT | REMOVE_PHYSICAL)) {
|
||||
/* Try to remove as subvolume first */
|
||||
r = btrfs_subvol_remove(path, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA);
|
||||
if (r >= 0)
|
||||
|
||||
Reference in New Issue
Block a user