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