Consolidate various TAKE_* into TAKE_GENERIC(), add TAKE_STRUCT()

This commit is contained in:
Dan Streetman
2023-01-24 18:33:43 +00:00
committed by Luca Boccassi
parent 98a1353014
commit 40c5cc2b21
4 changed files with 17 additions and 30 deletions
+2 -8
View File
@@ -90,14 +90,8 @@ static inline int make_null_stdio(void) {
return rearrange_stdio(-EBADF, -EBADF, -EBADF);
}
/* Like TAKE_PTR() but for file descriptors, resetting them to -1 */
#define TAKE_FD(fd) \
({ \
int *_fd_ = &(fd); \
int _ret_ = *_fd_; \
*_fd_ = -EBADF; \
_ret_; \
})
/* Like TAKE_PTR() but for file descriptors, resetting them to -EBADF */
#define TAKE_FD(fd) TAKE_GENERIC(fd, int, -EBADF)
/* Like free_and_replace(), but for file descriptors */
#define close_and_replace(a, b) \
+2 -8
View File
@@ -180,14 +180,8 @@ int get_oom_score_adjust(int *ret);
assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX);
/* Like TAKE_PTR() but for child PIDs, resetting them to 0 */
#define TAKE_PID(pid) \
({ \
pid_t *_ppid_ = &(pid); \
pid_t _pid_ = *_ppid_; \
*_ppid_ = 0; \
_pid_; \
})
/* Like TAKE_PTR() but for pid_t, resetting them to 0 */
#define TAKE_PID(pid) TAKE_GENERIC(pid, pid_t, 0)
int pidfd_get_pid(int fd, pid_t *ret);
int pidfd_verify_pid(int pidfd, pid_t pid);