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.
This commit is contained in:
+2
-4
@@ -731,8 +731,7 @@ int fd_duplicate_data_fd(int fd) {
|
||||
if (f != 0)
|
||||
return -errno;
|
||||
|
||||
safe_close(copy_fd);
|
||||
copy_fd = TAKE_FD(tmp_fd);
|
||||
CLOSE_AND_REPLACE(copy_fd, tmp_fd);
|
||||
|
||||
remains = mfree(remains);
|
||||
remains_size = 0;
|
||||
@@ -865,8 +864,7 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
|
||||
goto finish;
|
||||
}
|
||||
|
||||
safe_close(null_fd);
|
||||
null_fd = copy;
|
||||
CLOSE_AND_REPLACE(null_fd, copy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user