/* Make sure we can distinguish fd 0 and NULL */
#define FD_TO_PTR(fd) INT_TO_PTR((fd)+1)
#define PTR_TO_FD(p) (PTR_TO_INT(p)-1)
+#define PIPE_EBADF { -EBADF, -EBADF }
int close_nointr(int fd);
int safe_close(int fd);
int fd_nonblock(int fd, bool nonblock);
int fd_cloexec(int fd, bool cloexec);
+int fd_cloexec_many(const int fds[], size_t n_fds, bool cloexec);
int get_max_fd(void);
/* Like TAKE_PTR() but for file descriptors, resetting them to -1 */
#define TAKE_FD(fd) \
({ \
- int _fd_ = (fd); \
- (fd) = -1; \
- _fd_; \
+ int *_fd_ = &(fd); \
+ int _ret_ = *_fd_; \
+ *_fd_ = -EBADF; \
+ _ret_; \
})
/* Like free_and_replace(), but for file descriptors */
-#define CLOSE_AND_REPLACE(a, b) \
+#define close_and_replace(a, b) \
({ \
int *_fdp_ = &(a); \
safe_close(*_fdp_); \
})
int fd_reopen(int fd, int flags);
+int fd_reopen_condition(int fd, int flags, int mask, int *ret_new_fd);
int read_nr_open(void);
-int btrfs_defrag_fd(int fd);
+int fd_get_diskseq(int fd, uint64_t *ret);
/* The maximum length a buffer for a /proc/self/fd/<fd> path needs */
#define PROC_FD_PATH_MAX \