fd-util: add wildcard_fd_is_valid() helper and use it tree-wide
Many *at()-style helpers accept a directory fd that may be either a regular, valid fd (>= 0) or one of the special AT_FDCWD/XAT_FDROOT wildcard values, and open-code that check in their assertions. Add a wildcard_fd_is_valid() helper for it and use it tree-wide.
This commit is contained in:
committed by
Luca Boccassi
parent
d35fa257eb
commit
eb3799a373
@@ -142,7 +142,7 @@ int id128_read_fd(int fd, Id128Flag f, sd_id128_t *ret) {
|
||||
int id128_read_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t *ret) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
|
||||
assert(wildcard_fd_is_valid(dir_fd));
|
||||
assert(path);
|
||||
|
||||
fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
|
||||
|
||||
@@ -138,7 +138,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
|
||||
int id128_get_machine_at(int rfd, sd_id128_t *ret) {
|
||||
int r;
|
||||
|
||||
assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
|
||||
assert(wildcard_fd_is_valid(rfd));
|
||||
|
||||
r = dir_fd_is_root_or_cwd(rfd);
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user