1. Read Function
1) function prototype:
# Include <unistd. h>
Ssize_t read (int fd, void * Buf, size_t count );
2) function:
The read system calls to read count bytes from the file indicated by the file descriptor FD to the Buf.
3) parameter description:
FD: file descriptor
Buf: stores the cache of read information.
Count: number of bytes to read
Returned value: If the read operation succeeds, the number of bytes read is returned. If the read operation reaches the end, 0 is returned. An error occurs.
Return-1
2. Write function
1) function prototype:
# Include <unistd. h>
Ssize_t write (int fd, const void * Buf, size_t count );
2) function:
The write system calls to write the Count bytes of the buffer to which the Buf points to the file to which the FD points.
3) parameter description:
FD: file to be written
Buf: cache of the information to be written
Count: number of bytes to write
Returned value: If the write operation is successful, the number of written bytes is returned. If an error occurs, the value-1 is returned.
3. lseek Function
1) function prototype:
# Include <sys/types. h>
# Include <unistd. h>
Off_t lseek (INT Fildes, off_t offset, int whence );
2) function:
The lseek system call is used to move the read/write pointer position.
3) parameter description:
FD: file to be operated
Offset: the number of shifts relative to whence. Negative values are allowed.
Whence: Start pointer, which has three values
Seek_set calculates the offset from the beginning of the file
Seek_cur calculates the offset from the current position of the file pointer.
Seek_end calculates the offset from the end of the file.
The file pointer value is equal to the current pointer value plus the offset value.
Returned value: when the call is successful, the current read/write location, that is, the number of bytes from the start of the file. If
An error is returned.-1 is returned.
4) common usage:
Move the file read/write pointer to the beginning of the file:
Lseek (INT Fildes, 0, seek_set );
Move the file read/write pointer to the end of the file:
Lseek (INT Fildes, 0, seek_end );
Obtains the current position of the file read/write pointer.
Lseek (INT fikdes, 0, seek_cur );
Note: Some devices (or device files) cannot use lseek. Linux does not allow lseek () to operate on TTY devices. This operation causes the espipe error code within the range of lseek ().