C-language Open function syntax and its application

Source: Internet
Author: User

Open is a non-standard low-level file I/O function that returns a lower-level handle to the file, prototype:

int open (char* path, int access, ...). );

Open is a function implementation of a variable parameter, and the following variable parameter usually indicates whether the unsigned Mode,mode parameter exists to see the value of access, and path is the file.

The desirable values for access and mode are usually defined in FCNTL.h, and access's desirable values are as follows:

#define O_RDONLY          1

#define O_WRONLY          2

#define O_RDWR          4

access还可以是以下flag及它们之间的组合而得到的性质:

#define O_CREAT         0x0100     /* create and open file */

#define O_TRUNC         0x0200     /* open with truncation */

#define O_EXCL         0x0400     /* exclusive open */

#define O_APPEND              0x0800     /* to end of file */

#define O_CHANGED              0x1000     /* user may read these bits, but     */

#define O_DEVICE              0x2000     /* only RTL\io functions may touch.     */

#define O_TEXT         0x4000     /* CR-LF translation     */

#define O_BINARY              0x8000     /* no translation     */

When using O_creat, you must specify the mode parameter, and the value of mode is defined in the sys\stat.h, or it can be a combination of the following:

#define S_IREAD     0x0100     /* owner may read */

#define S_IWRITE   0x0080     /* owner may write */

Related Article

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.