1. read
# Include<Unistd. h>
Ssize_t read (int filedes, void * buf, size_t
Nbytes );
Returned value: the number of bytes read; 0 (read EOF);-1 (error)
The read function reads nbytes bytes from the opened file specified by filedes to the buf. In the following cases, the number of bytes read is smaller than that of nbytes.
:
A. When reading A common file, it is not enough nbytes bytes to read the end of the file. For example, if the file is only 30 bytes and we want to read 100 bytes, we only read 30 bytes.
Byte. The read function returns 30. Then, if you use the read function to act on this file, the read will return 0.
B. When reading data from a terminal device, generally only one row can be read at a time.
C. When reading data from the network, the network cache may cause the number of bytes to be read to be smaller than that of nbytes.
D. When reading pipe or FIFO, the number of bytes in pipe or FIFO may be less than nbytes.
E. When reading from a record-oriented device, some record-oriented devices (such as tapes) can only return one record at a time.
F. The signal is interrupted when some data is read.
The read operation starts with cfo. Cfo increases before the result is returned, and the increment is the number of bytes actually read.
2. write
# Include<Unistd. h>
Ssize_t write (int filedes, const void * buf, size_t
Nbytes );
Returned value: number of bytes written to the file (successful);-1 (error)
The write function writes nbytes bytes of data to filedes. The data source is buf. The returned value is always equal
Nbytes. Otherwise, an error occurs. A common error occurs when the disk space is full or exceeds the file size limit.
For common files, the write operation starts with cfo. If O_APPEND is used to open a file, data is written to the end of the file in each write operation. Cfo
Increment: the number of bytes actually written.