summaryrefslogtreecommitdiff
path: root/src/basic/fd-util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-16 15:36:44 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-18 15:28:48 +0200
commit0706c012598eee8372fb5d4ca6688ac5fb2380a4 (patch)
treec7764980023b427bcabbafa4813ae272681ffdb9 /src/basic/fd-util.h
parent831d57953e8e688128bc0f871d4b4213459842ba (diff)
downloadsystemd-0706c012598eee8372fb5d4ca6688ac5fb2380a4.tar.gz
Add CLOSE_AND_REPLACE helper
Similar to free_and_replace. I think this should be uppercase to make it clear that this is a macro. free_and_replace should probably be uppercased too.
Diffstat (limited to 'src/basic/fd-util.h')
-rw-r--r--src/basic/fd-util.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h
index e490753caf..93ce95cd03 100644
--- a/src/basic/fd-util.h
+++ b/src/basic/fd-util.h
@@ -93,6 +93,16 @@ static inline int make_null_stdio(void) {
_fd_; \
})
+/* Like free_and_replace(), but for file descriptors */
+#define CLOSE_AND_REPLACE(a, b) \
+ ({ \
+ int *_fdp_ = &(a); \
+ safe_close(*_fdp_); \
+ *_fdp_ = TAKE_FD(b); \
+ 0; \
+ })
+
+
int fd_reopen(int fd, int flags);
int read_nr_open(void);