fd-util: introduce fd_validate() helper
It just uses F_GETFD to validate an fd. it's a bit easier to read though, and handles the < 0 case internally.
This commit is contained in:
@@ -511,6 +511,16 @@ int pack_fds(int fds[], size_t n_fds) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd_validate(int fd) {
|
||||
if (fd < 0)
|
||||
return -EBADF;
|
||||
|
||||
if (fcntl(fd, F_GETFD) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int same_fd(int a, int b) {
|
||||
struct stat sta, stb;
|
||||
pid_t pid;
|
||||
|
||||
@@ -80,6 +80,7 @@ int close_all_fds_without_malloc(const int except[], size_t n_except);
|
||||
|
||||
int pack_fds(int fds[], size_t n);
|
||||
|
||||
int fd_validate(int fd);
|
||||
int same_fd(int a, int b);
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh);
|
||||
|
||||
Reference in New Issue
Block a user