]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/openat.2
Added comment on inconsistent naming of *at() functions.
[thirdparty/man-pages.git] / man2 / openat.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 2006, Michael Kerrisk
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\"
26 .TH OPENAT 2 2006-03-06 "Linux 2.6.16" "Linux Programmer's Manual"
27 .SH NAME
28 openat \- open a file at a relative location
29 .SH SYNOPSIS
30 .nf
31 .B #include <sys/types.h>
32 .B #include <sys/stat.h>
33 .B #include <fcntl.h>
34 .sp
35 .BI "int openat(int " dirfd ", const char *" pathname ", int " flags );
36 .BI "int openat(int " dirfd ", const char *" pathname ", int " flags \
37 ", mode_t " mode );
38 .fi
39 .SH DESCRIPTION
40 The
41 .BR openat ()
42 system call operates in exactly the same way as
43 .BR open (2),
44 except for the differences described in this manual page.
45
46 If the pathname given in
47 .I pathname
48 is relative, then it is interpreted relative to the directory
49 referred to by the file descriptor
50 .IR dirfd
51 (rather than relative to the current working directory of
52 the calling process, as is done by
53 .BR open (2)
54 for a relative pathname).
55
56 If the pathname given in
57 .I pathname
58 is relative and
59 .I dirfd
60 is the special value
61 .BR AT_FDCWD ,
62 then pathname is interpreted relative to the current working
63 directory of the calling process (like
64 .BR open (2)).
65
66 If the pathname given in
67 .IR pathname
68 is absolute, then
69 .I dirfd
70 is ignored.
71 .SH "RETURN VALUE"
72 .BR openat ()
73 returns a new file descriptor, or \-1 if an error occurred
74 (in which case,
75 .I errno
76 is set appropriately).
77 .SH ERRORS
78 The same errors that occur for
79 .BR open (2)
80 can also occur for
81 .BR openat (2).
82 The following additional errors can occur for
83 .BR openat ():
84 .TP
85 .B EBADF
86 .I dirfd
87 is not a valid file descriptor.
88 .TP
89 .B ENOTDIR
90 .I dirfd
91 is a file descriptor referring to a file other than a directory.
92 .SH NOTES
93 The
94 .BR openat ()
95 system call (and similar system calls suffixed "at")
96 provides functionality that can otherwise only be obtained
97 less efficiently or at the risk of races in user applications.
98 It allows the implementation of a per-thread "current working
99 directory", via file descriptor(s) maintained by the application.
100 (This functionality can also be obtained by tricks based
101 on the use of
102 .IR /proc/self/fd/ dirfd,
103 but less efficiently.)
104 It also allows the avoidance of various kinds of races that can occur
105 as a result of directory deletions that may occur while an application
106 is traversing a file system.
107 .SH "CONFORMING TO"
108 This system call is non-standard.
109 A similar system call exists on Solaris.
110 .\" The 'at' suffix in Solaris is actually double sensed. It
111 .\" primarily referred to "extended *at*tributes", which are
112 .\" handled by Solaris' O_XATTR flag, but was also intended
113 .\" to refer to the notion of "at a relative location".
114 .\"
115 .\" See also the following for a discussion of the inconsistent
116 .\" naming of the *at() functions:
117 .\" http://www.opengroup.org/austin/mailarchives/ag/msg09103.html
118 .\" Subject: RE: The naming of at()s is a difficult matter
119 .\" From: Don Cragun
120 .\" Date: Tue, 14 Feb 2006 14:56:50 -0800 (PST)
121 .\"
122 .SH VERSIONS
123 .BR openat ()
124 was added to Linux in kernel 2.6.16.
125 .SH "SEE ALSO"
126 .BR open (2),
127 .BR path_resolution (2)