Linux File I/O Comprehension

Source: Internet
Author: User

Linux File I/O operations can be divided into two types:

1. file IO operations with cache, including fopen, fclose, fread, fwrite, fgetc, fgets, fputc, fputs, freopen, fseek, ftell, and rewind

2. file IO operations without cache, including open, close, read, write, GETC, getchar, putc, putchar, etc.

 

Differences between the two:

1. Io operations with cache are defined (portable) in Standard C, and Io operations without cache are defined in POSIX (not portable) and are called by the system. Cache is actually based on no cache

Encapsulates a layer and maintains an input/output buffer so that it can be used across OS and become the ASCI standard.

2. fread can read a structure at a time. There is no difference between reading a binary file in Linux/Unix and reading a binary file in Linux/Unix.

3. fopen returns the file stream and open returns the file descriptor. A device file cannot be used as a stream file, but can only be used as an open file. in Linux/Unix, open or read can be used for all devices.

 

In addition, standard Io provides three different caching Methods

1. Full buffer. That is, data is written to the disk only when the buffer is full or fflush is called.

2. Row buffering. That is, the actual Io operation is performed only when the buffer is full or when a line break is encountered. When a stream involves a terminal (standard input and standard output), row buffering is usually used.

3. No buffer. The standard Io library does not cache characters. Standard Error stream stderr is usually not cached, so that error information can be displayed as soon as possible.

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.