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.)