int fcntl(int fd, int command, ... /* arg */ );
Is it portable: flags = fcntl(fd, F_GETFL);
(note: no arg
)?
Both Linux and FreeBSD man pages say that arg
is ignored:
F_GETFL (void)
Get the file access mode and the file status flags; arg
is ignored.
void
in Linux documentation means that arg
is not required.
Here's a usage example from POSIX for a related F_GETFD
flag:
#include <unistd.h>
#include <fcntl.h>
...
int flags;
flags = fcntl(fd, F_GETFD);
if (flags == -1)
/* Handle error */;
flags |= FD_CLOEXEC;
if (fcntl(fd, F_SETFD, flags) == -1)
/* Handle error */;"
It shows that arg
is not required for F_GETFD
(today). Then it says:
The arg values to F_GETFD, F_SETFD, F_GETFL, and F_SETFL all represent flag values to allow for future growth.
Does it imply that F_GETFL
might use arg
in the future?
A quick search for "F_GETFL" on Ohloh code creates an impression that most open-source projects do pass arg
(usually 0
, sometimes NULL
, or even (broken?) &fl
). I don't understand why fcntl(fd, F_GETFL, 0)
is the preferred form. @Wumpus Q. Wumbley suggests that it might be caused by "Advanced Programming in the UNIX Environment" book that also uses fcntl(fd, F_GETFL, 0)
form.
Is there a system/compiler that requires the 3rd arg: flags = fcntl(fd, F_GETFL, 0);
? Can fcntl(fd, F_GETFL)
and fcntl(fd, F_GETFL, 0)
produce different results today or in the future (assuming a compliant implementation)?