1OPENAT(2)                  Linux Programmer's Manual                 OPENAT(2)
2
3
4

NAME

6       openat - open a file relative to a directory file descriptor
7

SYNOPSIS

9       #include <fcntl.h>
10
11       int openat(int dirfd, const char *pathname, int flags);
12       int openat(int dirfd, const char *pathname, int flags, mode_t mode);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       openat():
17       Since glibc 2.10: _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
18       Before glibc 2.10: _ATFILE_SOURCE
19

DESCRIPTION

21       The  openat()  system call operates in exactly the same way as open(2),
22       except for the differences described in this manual page.
23
24       If the pathname given in pathname is relative, then it  is  interpreted
25       relative  to  the  directory  referred  to by the file descriptor dirfd
26       (rather than relative to the current working directory of  the  calling
27       process, as is done by open(2) for a relative pathname).
28
29       If  pathname  is relative and dirfd is the special value AT_FDCWD, then
30       pathname is interpreted relative to the current  working  directory  of
31       the calling process (like open(2)).
32
33       If pathname is absolute, then dirfd is ignored.
34

RETURN VALUE

36       On  success,  openat()  returns a new file descriptor.  On error, -1 is
37       returned and errno is set to indicate the error.
38

ERRORS

40       The same errors that occur for open(2) can  also  occur  for  openat().
41       The following additional errors can occur for openat():
42
43       EBADF  dirfd is not a valid file descriptor.
44
45       ENOTDIR
46              pathname is relative and dirfd is a file descriptor referring to
47              a file other than a directory.
48

VERSIONS

50       openat() was added to Linux in kernel 2.6.16.
51

CONFORMING TO

53       POSIX.1-2008.  A similar system call exists on Solaris.
54

NOTES

56       openat() and other similar system calls suffixed "at" are supported for
57       two reasons.
58
59       First,  openat()  allows  an  application to avoid race conditions that
60       could occur when using open(2) to open files in directories other  than
61       the  current  working directory.  These race conditions result from the
62       fact that some component of the directory prefix given to open(2) could
63       be  changed  in  parallel  with the call to open(2).  Such races can be
64       avoided by opening a file descriptor for the target directory, and then
65       specifying that file descriptor as the dirfd argument of openat().
66
67       Second,  openat()  allows  the  implementation of a per-thread "current
68       working directory", via file descriptor(s) maintained by  the  applica‐
69       tion.   (This functionality can also be obtained by tricks based on the
70       use of /proc/self/fd/dirfd, but less efficiently.)
71

SEE ALSO

73       faccessat(2),  fchmodat(2),  fchownat(2),   fstatat(2),   futimesat(2),
74       linkat(2), mkdirat(2), mknodat(2), open(2), readlinkat(2), renameat(2),
75       symlinkat(2),  unlinkat(2),  utimensat(2),  mkfifoat(3),   path_resolu‐
76       tion(7)
77

COLOPHON

79       This  page  is  part of release 3.25 of the Linux man-pages project.  A
80       description of the project, and information about reporting  bugs,  can
81       be found at http://www.kernel.org/doc/man-pages/.
82
83
84
85Linux                             2009-12-13                         OPENAT(2)
Impressum