Linux file IO

Source: Internet
Author: User

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:

    1. O_rdonly: Open File as read-only
    2. O_wronly: Open File as Write-only
    3. 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

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.