Read from a file without moving the file pointer
#include <unistd.h> ssize_t pread(int filedes, void *buff, size_t nbytes, off_t offset ); ssize_t pread64( int filedes, void *buff, size_t nbytes, off64_t offset );
- The descriptor of the file that you want to read from.
- A pointer to a buffer where the function can store the data that it reads.
- The number of bytes that you want to read.
- The desired position inside the file.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The pread() function performs the same action as read() , except that it reads from a given position in the file without changing the file pointer.
The pread() function reads up to the maximum offset value that can be represented in an off_t for regular files. An attempt to perform a pread() on a file that's incapable of seeking results in an error.
The pread64() function is a 64-bit version of pread().
The number of bytes actually read, or -1 if an error occurred (errno is set).
- The O_NONBLOCK flag is set for the file descriptor, and the process would be delayed in the read operation.
- The file descriptor, fildes, isn't a valid file descriptor open for reading.
- The read operation was interrupted by a signal, and either no data was transferred, or the resource manager responsible for that file does not report partial transfers.
- A physical I/O error occurred (for example, a bad block on a disk). The precise meaning is device-dependent.
- The pread() function isn't implemented for the filesystem specified by filedes.