diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-03-22 17:04:29 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-03-22 20:30:40 +0100 |
commit | c10d6bdb891881f68471dabd8100ea6021e6cdbb (patch) | |
tree | 99f77908217b88a1b49c1ef23d1e27c493ba30e4 /src/basic/fd-util.h | |
parent | sleep-config: replace USE() macro with TAKE_PTR() usage (diff) | |
download | systemd-c10d6bdb891881f68471dabd8100ea6021e6cdbb.tar.xz systemd-c10d6bdb891881f68471dabd8100ea6021e6cdbb.zip |
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.
Diffstat (limited to 'src/basic/fd-util.h')
-rw-r--r-- | src/basic/fd-util.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 635a538b5a..007580b48f 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -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_; \ + }) |