1 #ifndef FD_UTIL_H 2 #define FD_UTIL_H 3 4 /* Change close-on-exec flag of fd. */ 5 void fd_close_on_exec(int fd, bool set); 6 7 /* Verify that fds in given range don't exist. */ 8 void fd_debug_verify_leaks(int first_fd, int last_fd); 9 10 /* Set file descriptor to blocking/nonblocking state */ 11 void fd_set_nonblock(int fd, bool nonblock); 12 13 /* Close fd_in and fd_out, unless they're already -1. They can point to the 14 same fd, in which case they're closed only once. If they point to stdin 15 or stdout, they're replaced with /dev/null. */ 16 void fd_close_maybe_stdio(int *fd_in, int *fd_out); 17 18 /* Close the fd and set it to -1. This assert-crashes if fd == 0, and is a 19 no-op if fd == -1. Normally fd == 0 would happen only if an uninitialized 20 fd is attempted to be closed, which is a bug. */ 21 void i_close_fd_path(int *fd, const char *path, const char *arg, 22 const char *func, const char *file, int line); 23 #define i_close_fd_path(fd, path) i_close_fd_path((fd), (path), #fd, __func__, __FILE__, __LINE__) 24 #define i_close_fd(fd) i_close_fd_path((fd), NULL) 25 26 #endif 27