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