MACRO: integer constant o_accmode

Source: Internet
Author: User

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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.