pread(), pread64()

Read from a file without moving the file pointer

Synopsis:

#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 );

Arguments:

filedes
The descriptor of the file that you want to read from.
buff
A pointer to a buffer where the function can store the data that it reads.
nbytes
The number of bytes that you want to read. This amount must not exceed SSIZE_MAX (see <limits.h>), or the function fails and sets errno to EOVERFLOW.
offset
The desired position inside the file.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The pread() and pread64() functions perform the same action as read(), except that they read from a given position in the file without changing the file pointer. The pread64() function is a large-file support version of pread().

Note:
In QNX Neutrino 6.6 or later, the large-file support functions and data types appear in the name space only if you define _LARGEFILE64_SOURCE when you compile your code. For more information, see Classification in What's in a Function Description?

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.

Returns:

The number of bytes actually read, or -1 if an error occurred (errno is set).

Errors:

EAGAIN
The O_NONBLOCK flag is set for the file descriptor, and the process would be delayed in the read operation.
EBADE
The number of bytes read as reported by the resmgr is invalid. This usually reflects a bug in the resmgr itself.
EBADF
The file descriptor, filedes, isn't a valid file descriptor open for reading.
EINTR
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.
EINVAL
The offset argument is invalid; the value is negative.
EIO
A physical I/O error occurred (for example, a bad block on a disk). The precise meaning is device-dependent.
EISDIR
The file descriptor is for a directory.
ENOSYS
The pread() function isn't implemented for the filesystem specified by filedes.
EOVERFLOW
An attempt was made to read an amount of data that exceeds the allowable limit.

Classification:

pread() is POSIX 1003.1; pread64() is Large-file support

Safety:
Cancellation pointYes
Interrupt handlerNo
Signal handlerYes
ThreadYes
Page updated: