macro: introduce new TAKE_FD() macro
This is similar to TAKE_PTR() but operates on file descriptors, and thus assigns -1 to the fd parameter after returning it. Removes 60 lines from our codebase. Pretty good too I think.
This commit is contained in:
@@ -105,3 +105,11 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
|
||||
static inline int make_null_stdio(void) {
|
||||
return rearrange_stdio(-1, -1, -1);
|
||||
}
|
||||
|
||||
/* Like TAKE_PTR() but for file descriptors, resetting them to -1 */
|
||||
#define TAKE_FD(fd) \
|
||||
({ \
|
||||
int _fd_ = (fd); \
|
||||
(fd) = -1; \
|
||||
_fd_; \
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user