read function in Linux

Tuesday night, July 11, 2023


In Linux, the read() function is a system call for reading data from a file descriptor (file descriptor).

The header file is unistd.h

Its prototype is as follows:

#include <unistd.h>

ssize_t read(int fd, void *buf, size_t count);
  • fd: The file descriptor to read, which can be an open file, socket, pipe, etc.
  • buf: Pointer to the buffer used to store the read data.
  • count: The maximum number of bytes to read.

The return value of the read() function is the number of bytes that have been read. If the return value is 0, it means that the end of the file (End-Of-File) has been reached. If the return value is -1, it means that the read error has occurred.

Guess you like

Origin blog.csdn.net/m0_61629312/article/details/131670392