Section: Linux Programmer's Manual (2)
Return to Main Contents
openat - open a file relative to a directory file descriptor
int openat(int dirfd, const char *pathname, int flags);
int openat(int dirfd, const char *pathname, int flags, mode_t mode);
Feature Test Macro Requirements for glibc (see
- Since glibc 2.10:
_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
- Before glibc 2.10:
system call operates in exactly the same way as
except for the differences described in this manual page.
If the pathname given in
is relative, then it is interpreted relative to the directory
referred to by the file descriptor
(rather than relative to the current working directory of
the calling process, as is done by
for a relative pathname).
is relative and
is the special value
is interpreted relative to the current working
directory of the calling process (like
is absolute, then
returns a new file descriptor.
On error, -1 is returned and
is set to indicate the error.
The same errors that occur for
can also occur for
The following additional errors can occur for
is not a valid file descriptor.
is relative and
is a file descriptor referring to a file other than a directory.
was added to Linux in kernel 2.6.16.
A similar system call exists on Solaris.
and other similar system calls suffixed "at" are supported
for two reasons.
allows an application to avoid race conditions that could
occur when using
to open files in directories other than the current working directory.
These race conditions result from the fact that some component
of the directory prefix given to
could be changed in parallel with the call to
Such races can be avoided by
opening a file descriptor for the target directory,
and then specifying that file descriptor as the
allows the implementation of a per-thread "current working
directory", via file descriptor(s) maintained by the application.
(This functionality can also be obtained by tricks based
on the use of
but less efficiently.)
This page is part of release 3.27 of the Linux
A description of the project,
and information about reporting bugs,
can be found at
- RETURN VALUE
- CONFORMING TO
- SEE ALSO
This document was created by
using the manual pages.