[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fcntl module
From: |
Bruno Haible |
Subject: |
Re: fcntl module |
Date: |
Mon, 24 Aug 2009 11:21:22 +0200 |
User-agent: |
KMail/1.9.9 |
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
- Re: fcntl module, (continued)
- Re: fcntl module, Eric Blake, 2009/08/22
- Re: fcntl module, Bruno Haible, 2009/08/23
- Re: fcntl module, Eric Blake, 2009/08/23
- Re: fcntl module, Eric Blake, 2009/08/23
- Re: O_SAFER (was: fcntl module), Bruno Haible, 2009/08/24
- Re: O_SAFER, Paolo Bonzini, 2009/08/24
- Re: O_SAFER, Eric Blake, 2009/08/24
- Re: fcntl module,
Bruno Haible <=
- [PATCH] Move more flags to lib/fcntl.in.h, Paolo Bonzini, 2009/08/20
- Re: [PATCH] Move more flags to lib/fcntl.in.h, Eric Blake, 2009/08/20
- Re: [PATCH] Move more flags to lib/fcntl.in.h, Bruno Haible, 2009/08/22
- Re: O_CLOEXEC support (was: popen bugs, popen_safer), Bruno Haible, 2009/08/22
- Re: O_CLOEXEC support, Paolo Bonzini, 2009/08/22
Re: popen bugs, popen_safer, Bruno Haible, 2009/08/20