The file access modes allow a file descriptor to be used for reading, writing, or both. (On GNU/Hurd systems, they can also allow none of these, and allow execution of the file as a program.) The access modes are chosen when the file is opened, and never change.
On GNU/Hurd systems (and not on other systems),
O_WRONLY are independent bits that can be bitwise-ORed together,
and it is valid for either bit to be set or clear. This means that
O_RDWR is the same as
O_RDONLY|O_WRONLY. A file access
mode of zero is permissible; it allows no operations that do input or
output to the file, but does allow other operations such as
fchmod. On GNU/Hurd systems, since “read-only” or “write-only”
is a misnomer, fcntl.h defines additional names for the file
access modes. These names are preferred when writing GNU-specific code.
But most programs will want to be portable to other POSIX.1 systems and
should use the POSIX.1 names above instead.
To determine the file access mode with
fcntl, you must extract
the access mode bits from the retrieved file status flags. On
you can just test the
O_WRITE bits in
the flags word. But in other POSIX.1 systems, reading and writing
access modes are not stored as distinct bit flags. The portable way to
extract the file access mode bits is with