The open () function uses the Open function in Linux

Source: Internet
Author: User

Source: http://www.cnblogs.com/songfeixiang/p/3733855.html

The open function in Linux usesThe open function is used to turn on a device, and he returns an integer variable if the value equals-1, indicating an error opening the file, if the value is greater than 0
Reference format if (Fd=open ("/dev/ttys0", O_RDWR | O_noctty | O_ndelay)) <0 {printf ("Cannot open"};
int open (const char *pathname, int oflag, .../*,mode_t mode */);
There are several types of operations open:
1) o_rdonly read-only Open
2) o_wronly only write Open
3) O_rdwr read, write open
4) O_append is added to the end of the file each time it is written
5) O_creat If this file does not exist, create it. When using this selection, it is necessary to describe the third parameter mode, which describes the access permission of the new file to the throne.
6) O_EXCL If O_creat is specified and the file already exists, an error occurs. This tests whether a file exists and if it does not, it becomes an atomic operation to create the file.
7) O_trunc If this file exists and is open for read-only or write-only success, truncate it to 0 length.
8) O_noctty if p a t h n a me refers to an end device, then this equipment is not assigned as the control terminal of this process.
9) O_nonblock if p a t h n a me refers to an F I F O, a block special file, or a character special file, this option sets the non-blocking mode for this open operation and subsequent I/O operations for this file.
O_sync makes every w r i T e wait until the physical I/O operation is complete.
These control words are separated by the "or" symbol (|)

The open () function uses the Open function in Linux

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.