Reference <unix Advanced Environment Programming "
This chapter begins with the discussion of the U-N I x system, which first describes the available file I/O functions-opening files, reading files, writing files, and so on.
Most u N i x file I/O requires only 5 functions: O p e N, r e a D, W r i t e, Lseek, and C l o S E. Then explain the different slow
The effect of the length of the register on R-E a D and W r i T-e functions.
In P O S I X. 1 applications, the magic number 0, 1, 2 should be replaced by symbolic constants S T d i n_ f i l e n o, s t d o U t_ f i l e n o and s T d e R r_ f i l e n o. These constants are defined in the header file < u n i s t d. H > in.
int open (const char* pathname,int oflag,...)
The first parameter is used to specify the path and name of the file to be opened, and the two parameter is used to specify how the file is opened, the three parameter ... Indicates that there can be any number of arguments of any type, but the third parameter is used to specify the permissions of the new file only if you create it with the open function. The second parameter can have a choice of:
- O_rdonly: Open File as read-only
- O_wronly: Open File as Write-only
- O_RDWR: Open a file in a readable and writable manner
In fact, the values of the three choices for the polygon are 0, 1, and 2, respectively. One of the easiest mistakes to make when learning Linux programming is that when a file is opened in a readable and writable manner, it is written in the following form:
the file descriptor returned by O p e n must be the smallest unused descriptor number. This point is used by many applications to
Open a new file on a quasi-input, standard output, or standard error output. For example, an application can first close the standard
Output (usually file descriptor 1), and then open another file, you will know beforehand that the file must be in the file description
Open on the character 1. In the 3. 1 2 section describes the D U P 2 function, you can learn that there is a better way to ensure that a given descriptor
Open a file on the.
Linux file IO