posix_fadvise(), posix_fadvise64()

Updated: April 19, 2023

Provide advisory information about the expected use of a file

Synopsis:

#include <fcntl.h>

int posix_fadvise( int fd,
                   off_t offset,
                   size_t len,
                   int advice );

int posix_fadvise64( int fd,
                     off64_t offset,
                     size_t len,
                     int advice );

Arguments:

fd
An open file descriptor.
offset
The offset of the data about which you want to provide advice.
len
The length of the data.
advice
The advice you want to give; one of:
  • POSIX_FADV_NORMAL — the application has no advice to give on its behavior with respect to the specified data. This is the default characteristic if no advice is given for an open file.
  • POSIX_FADV_SEQUENTIAL — the application expects to access the specified data sequentially from lower offsets to higher offsets.
  • POSIX_FADV_RANDOM — the application expects to access the specified data in a random order.
  • POSIX_FADV_WILLNEED — the application expects to access the specified data in the near future.
  • POSIX_FADV_DONTNEED — the application expects that it will not access the specified data in the near future.
  • POSIX_FADV_NOREUSE — the application expects to access the specified data once and then not reuse it thereafter.

Library:

libc

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

Description:

The posix_fadvise() and posix_fadvise64() functions advise the filesystem how the application expects to use the data in the file associated with the open file descriptor, fd, starting at offset and continuing for len bytes. The posix_fadvise64() is a large-file support version of posix_fadvise().

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 specified range need not currently exist in the file. If len is zero, all data following offset is specified. The filesystem may use this information to optimize handling of the specified data. The posix_fadvise() function has no effect on the semantics of other operations on the specified data, although it may affect the performance of other operations.

Returns:

0
Success.
EBADF
The fd argument isn't a valid file descriptor.
EINVAL
The value of advice is invalid, or len is less than zero.
ESPIPE
The fd argument is associated with a pipe, FIFO, or socket.

Classification:

posix_fadvise() is POSIX 1003.1 ADV; posix_fadvise64() is Large-file support

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes