From: Christian Brauner Date: Tue, 2 Feb 2021 12:44:13 +0000 (+0100) Subject: memory_utils: add close_prot_errno_mov() X-Git-Tag: lxc-5.0.0~306^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c6c4794dc0c7f51980071216c906fa586e82ebb;p=thirdparty%2Flxc.git memory_utils: add close_prot_errno_mov() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/memory_utils.h b/src/lxc/memory_utils.h index d3b68a1e9..a7a9afcf3 100644 --- a/src/lxc/memory_utils.h +++ b/src/lxc/memory_utils.h @@ -29,6 +29,15 @@ fd = -EBADF; \ } +#define close_prot_errno_move(fd, new_fd) \ + if (fd >= 0) { \ + int _e_ = errno; \ + close(fd); \ + errno = _e_; \ + fd = new_fd; \ + new_fd = -EBADF; \ + } + static inline void close_prot_errno_disarm_function(int *fd) { close_prot_errno_disarm(*fd);