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:
Lennart Poettering
2018-03-22 20:30:40 +01:00
parent 2f4cefe6ce
commit c10d6bdb89
25 changed files with 64 additions and 130 deletions
+8
View File
@@ -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_; \
})