Original article:
-
MACRO:Int O_accmode
-
This macro stands for a mask that can be bitwise-anded with the file status flag value to produce a value representing the file access mode. The mode will be
O_RDONLY, O_WRONLY, Or O_RDWR. (In the GNU system it cocould also be zero, and it never implements des O_EXECBit .)
Translation:
This macro acts as a mask to perform and bitwise operations with the file status Identifier value to generate a value indicating the file access mode. This mode will be o_rdonly, o_wronly, or o_rdwr (in the GNU system, it may also be zero and never include the o_exec bit)
O_accmode <0003>: when reading and writing files, it is used to retrieve the low 2-Bit Flag
O_rdonly <00>: Read-Only
O_wronly <01>: Write-only open
O_rdwr <02>: read/write Enabled
# Include "apue. H"
# Include <fcntl. h>
Int
Main (INT argc, char * argv [])
{
Int val;
If (argc! = 2)
Err_quit ("Usage: A. Out <descriptor #> ");
If (val = fcntl (atoi (argv [1]), f_getfl, 0) <0)
Err_sys ("fcntl error for fd % d", atoi (argv [1]);
Switch (Val & o_accmode ){
Case o_rdonly:
Printf ("Read Only ");
Break;
Case o_wronly:
Printf ("write only ");
Break;
Case o_rdwr:
Printf ("read write ");
Break;
Default:
Err_dump ("unknown access mode ");
}
If (Val & o_append)
Printf (", append ");
If (Val & o_nonblock)
Printf (", nonblocking ");
# If defined (o_sync)
If (Val & o_sync)
Printf (", synchronous writes ");
# Endif
# If! Defined (_ posix_c_source) & defined (o_fsync)
If (Val & o_fsync)
Printf (", synchronous writes ");
# Endif
Putchar ('/N ');
Exit (0 );
}