diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-03-22 17:04:29 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-08-24 16:47:08 +0200 |
commit | f2e5755be31573b10852c9e8bd97a9881e925758 (patch) | |
tree | 80ca4f27ea58b3d71dd6a3bbc91f6ffe152fa2a5 /src/basic/fd-util.h | |
parent | c280e28425e1f9a55a2bdbe3c988a56280c8bfdb (diff) |
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 | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 4cdd01bee..cb4677ec4 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -102,10 +102,6 @@ int acquire_data_fd(const void *data, size_t size, unsigned flags); #define ERRNO_IS_DISCONNECT(r) \ IN_SET(r, ENOTCONN, ECONNRESET, ECONNREFUSED, ECONNABORTED, EPIPE, ENETUNREACH) -/* Resource exhaustion, could be our fault or general system trouble */ -#define ERRNO_IS_RESOURCE(r) \ - IN_SET(r, ENOMEM, EMFILE, ENFILE) - int fd_move_above_stdio(int fd); int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd); @@ -113,3 +109,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_; \ + }) |