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.c | |
parent | 2f4cefe6ce00a38988830e88f7b16acfb6b21b3c (diff) | |
download | systemd-c10d6bdb891881f68471dabd8100ea6021e6cdbb.tar.gz |
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.c')
-rw-r--r-- | src/basic/fd-util.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 6d7875361c..0726aac38c 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -484,10 +484,7 @@ int acquire_data_fd(const void *data, size_t size, unsigned flags) { if (r < 0) return r; - r = fd; - fd = -1; - - return r; + return TAKE_FD(fd); } try_pipe: @@ -524,10 +521,7 @@ try_pipe: (void) fd_nonblock(pipefds[0], false); - r = pipefds[0]; - pipefds[0] = -1; - - return r; + return TAKE_FD(pipefds[0]); } try_dev_shm: |