mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
Add yet another tiny helper to manipulate flags
This commit is contained in:
parent
7d6342e401
commit
0da965037e
@ -175,11 +175,7 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) {
|
||||
if (ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags) < 0)
|
||||
return -errno;
|
||||
|
||||
if (b)
|
||||
nflags = flags | BTRFS_SUBVOL_RDONLY;
|
||||
else
|
||||
nflags = flags & ~BTRFS_SUBVOL_RDONLY;
|
||||
|
||||
nflags = UPDATE_FLAG(flags, BTRFS_SUBVOL_RDONLY, b);
|
||||
if (flags == nflags)
|
||||
return 0;
|
||||
|
||||
|
@ -144,11 +144,7 @@ int fd_nonblock(int fd, bool nonblock) {
|
||||
if (flags < 0)
|
||||
return -errno;
|
||||
|
||||
if (nonblock)
|
||||
nflags = flags | O_NONBLOCK;
|
||||
else
|
||||
nflags = flags & ~O_NONBLOCK;
|
||||
|
||||
nflags = UPDATE_FLAG(flags, O_NONBLOCK, nonblock);
|
||||
if (nflags == flags)
|
||||
return 0;
|
||||
|
||||
@ -167,11 +163,7 @@ int fd_cloexec(int fd, bool cloexec) {
|
||||
if (flags < 0)
|
||||
return -errno;
|
||||
|
||||
if (cloexec)
|
||||
nflags = flags | FD_CLOEXEC;
|
||||
else
|
||||
nflags = flags & ~FD_CLOEXEC;
|
||||
|
||||
nflags = UPDATE_FLAG(flags, FD_CLOEXEC, cloexec);
|
||||
if (nflags == flags)
|
||||
return 0;
|
||||
|
||||
|
@ -451,8 +451,10 @@ static inline int __coverity_check_and_return__(int condition) {
|
||||
ans; \
|
||||
})
|
||||
|
||||
#define UPDATE_FLAG(orig, flag, b) \
|
||||
((b) ? ((orig) | (flag)) : ((orig) & ~(flag)))
|
||||
#define SET_FLAG(v, flag, b) \
|
||||
(v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
|
||||
(v) = UPDATE_FLAG(v, flag, b)
|
||||
#define FLAGS_SET(v, flags) \
|
||||
((~(v) & (flags)) == 0)
|
||||
|
||||
|
@ -135,10 +135,7 @@ int efi_set_reboot_to_firmware(bool value) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (value)
|
||||
b_new = b | EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
|
||||
else
|
||||
b_new = b & ~EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
|
||||
b_new = UPDATE_FLAG(b, EFI_OS_INDICATIONS_BOOT_TO_FW_UI, value);
|
||||
|
||||
/* Avoid writing to efi vars store if we can due to firmware bugs. */
|
||||
if (b != b_new)
|
||||
|
Loading…
Reference in New Issue
Block a user