Linux raw io and standard IO

Source: Internet
Author: User
Tags fread

There are two types of IO in Linux programming, one is the IO function provided by the standard library fopen, Fread, fwrite. A class is the System interface function read, write, and so on. This article explains the differences and linkages between the two types of IO.

Difference:

First look at the definitions of the two types of IO functions:

Fread: size_t fread ( void *buffer, size_t size, size_t count, FILE *stream);

read: ssize_t read (int fd, void *buf, size_t count);

1. fread needs the incoming file pointer to read the data from the file pointer, and the read function reads the data from an shaping file descriptor.

As an example of standard input, Fread needs to pass in the stdin file pointer as a parameter, and read needs to pass in Stdin_fileno.

The 2.fread function has the function of caching, and the read function does not have the function of caching, which means that the read

Fread calls the Read System interface API to read a large piece of data from the kernel to the cache provided by the library, and then reads the data from the cache (size bytes) to the user-supplied buffer.

Read only reads a fixed count byte from the kernel

3.fread can only read data from a file, read reads from the file descriptor, the file descriptor does not necessarily represent the file, it can be a socket or a pipe.

4. header file is not the same, read header file is <fcntl.h> <sys/types.h>,<sys.stat.h>,<unistd.h>

Fread header file Stdio.h represents reading data from a file stream

Contact:

The Fread function belongs to the C standard library function, and its function is to invoke the system interface read implementation.

Linux raw io and standard 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.