File I/O

Source: Internet
Author: User

A file operation typically uses 5 functions:

Open, read, write, Lseek, close

For the kernel, all open files are referenced by a file descriptor (non-negative integer). When an existing file is opened or a new file is created, the kernel returns a file descriptor to the process.

When reading and writing a file, use open or creat to return a file descriptor to identify the file and pass its arguments to read or write.

The UNIX system shell uses file descriptors 0, 1, and 2, respectively, associated with the process's standard input, standard output, and standard error output.

In a POSIX-compliant application, the magic number 0, 1, and 2 should be replaced with symbolic constants Stdin_fileno, Stdout_fileno, Stderr_fileno, defined in the header file <unistd.h>.

Open function

Oflag constants include: O_rdonly, O_wronly, O_rdwr, O_append, O_creat, and so on.

Lseek function

Sets the current file offset. The whence value can be

File I/O

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.