Skip to content

Commit 34770be

Browse files
committed
shared: sync TAKE_FD() from systemd
Used version from systemd/systemd@90d5967 since the current upstream implementation via TAKE_GENERIC is not available here.
1 parent a896ad5 commit 34770be

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/share/fd-util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ void cmsg_close_all(struct msghdr *mh);
4949
/* Hint: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5 */
5050
#define ERRNO_IS_DISCONNECT(r) \
5151
IN_SET(r, ENOTCONN, ECONNRESET, ECONNREFUSED, ECONNABORTED, EPIPE, ENETUNREACH)
52+
53+
/* Like TAKE_PTR() but for file descriptors, resetting them to -1 */
54+
#define TAKE_FD(fd) \
55+
({ \
56+
int *_fd_ = &(fd); \
57+
int _ret_ = *_fd_; \
58+
*_fd_ = -1; \
59+
_ret_; \
60+
})

0 commit comments

Comments
 (0)