Eric Blake wrote: > most users go via > "unistd--.h" which can adjust the #define appropriately.
Good point. So we can go with a generic primitive under the hood, and don't need to provide the *_safer variant as a function - as a macro it is enough. > /* Duplicate FD into a new file descriptor, at least as large as MINIMUM, > and first closing any existing fd at minimum if OVERWRITE. FLAGS can > contain O_CLOEXEC, O_TEXT, or O_BINARY. */ > gl_dup (int fd, int minimum, int flags, bool overwrite) > > dup (n) -> gl_dup (n, 0, 0, false) > dup2 (n, m) -> gl_dup (n, m, 0, true) > dup3 (n, m, flags) -> gl_dup (n, m, flags, true) > fcntl (n, F_DUPFD, m) -> gl_dup (n, m, 0, false) > fcntl (n, F_DUPFD_CLOEXEC, m) -> gl_dup (n, m, O_CLOEXEC, false) > dup_safer (n) -> gl_dup (n, 3, 0, false) > dup_safer_noinherit (n) -> gl_dup (n, 3, O_CLOEXEC, false) Unfortunately dup2(n,n) and dup3(n,n,0) don't work the same - see <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. Therefore only dup2 or dup3 can be accomodated into the common gl_dup function. And since it's only one of them, there is actually not much point in providing the 'bool overwrite' parameter at all: users can call dup3 instead of gl_dup (n, m, flags, true). So we're back to gl_dup (int fd, int minimum, int flags). > > pipe2_ex (int fd[2], int flags, int minimum) > > Seems okay (although maybe the name gl_pipe2 is better than pipe2_ex): A disadvantage of 'gl_dup', 'gl_pipe2' is that it does not convey the message what is changed relative to 'dup' and 'pipe2'. Additionally, the naming of the gnulib module would be strange. I would prefer a suffix 'o' (as in 'mkostemp') for the O_* flags argument, and 'm' for the minimum return value: dupom (int fd, int minimum, int flags) pipe2m (int fd[2], int flags, int minimum) accept4m (int s, struct sockaddr *addr, socklen_t *addrlen, int flags, int minimum) Bruno
