OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / 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 2009-12-13 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 openat \- open a file relative to a directory file descriptor
29 .SH SYNOPSIS
30 .nf
31 .B #include <fcntl.h>
32 .sp
33 .BI "int openat(int " dirfd ", const char *" pathname ", int " flags );
34 .BI "int openat(int " dirfd ", const char *" pathname ", int " flags \
35 ", mode_t " mode );
36 .fi
37 .sp
38 .in -4n
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
41 .in
42 .sp
43 .BR openat ():
44 .PD 0
45 .ad l
46 .RS 4
47 .TP 4
48 Since glibc 2.10:
49 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
50 .TP
51 Before glibc 2.10:
52 _ATFILE_SOURCE
53 .RE
54 .ad
55 .PD
56 .SH DESCRIPTION
57 The
58 .BR openat ()
59 system call operates in exactly the same way as
60 .BR open (2),
61 except for the differences described in this manual page.
62
63 If the pathname given in
64 .I pathname
65 is relative, then it is interpreted relative to the directory
66 referred to by the file descriptor
67 .I dirfd
68 (rather than relative to the current working directory of
69 the calling process, as is done by
70 .BR open (2)
71 for a relative pathname).
72
73 If
74 .I pathname
75 is relative and
76 .I dirfd
77 is the special value
78 .BR AT_FDCWD ,
79 then
80 .I pathname
81 is interpreted relative to the current working
82 directory of the calling process (like
83 .BR open (2)).
84
85 If
86 .I pathname
87 is absolute, then
88 .I dirfd
89 is ignored.
90 .SH "RETURN VALUE"
91 On success,
92 .BR openat ()
93 returns a new file descriptor.
94 On error, \-1 is returned and
95 .I errno
96 is set to indicate the error.
97 .SH ERRORS
98 The same errors that occur for
99 .BR open (2)
100 can also occur for
101 .BR openat ().
102 The following additional errors can occur for
103 .BR openat ():
104 .TP
105 .B EBADF
106 .I dirfd
107 is not a valid file descriptor.
108 .TP
109 .B ENOTDIR
110 .I pathname
111 is relative and
112 .I dirfd
113 is a file descriptor referring to a file other than a directory.
114 .SH VERSIONS
115 .BR openat ()
116 was added to Linux in kernel 2.6.16.
117 .SH "CONFORMING TO"
118 POSIX.1-2008.
119 A similar system call exists on Solaris.
120 .\" The 'at' suffix in Solaris is actually double sensed.  It
121 .\" primarily referred to "extended *at*tributes", which are
122 .\" handled by Solaris' O_XATTR flag, but was also intended
123 .\" to refer to the notion of "at a relative location".
124 .\"
125 .\" See the following for a discussion of the inconsistent
126 .\" naming of the *at() functions:
127 .\" http://www.opengroup.org/austin/mailarchives/ag/msg09103.html
128 .\" Subject:    RE: The naming of at()s is a difficult matter
129 .\" From:       Don Cragun
130 .\" Date:       Tue, 14 Feb 2006 14:56:50 -0800 (PST)
131 .\"
132 .SH NOTES
133 .BR openat ()
134 and other similar system calls suffixed "at" are supported
135 for two reasons.
136
137 First,
138 .BR openat ()
139 allows an application to avoid race conditions that could
140 occur when using
141 .BR open (2)
142 to open files in directories other than the current working directory.
143 These race conditions result from the fact that some component
144 of the directory prefix given to
145 .BR open (2)
146 could be changed in parallel with the call to
147 .BR open (2).
148 Such races can be avoided by
149 opening a file descriptor for the target directory,
150 and then specifying that file descriptor as the
151 .I dirfd
152 argument of
153 .BR openat ().
154
155 Second,
156 .BR openat ()
157 allows the implementation of a per-thread "current working
158 directory", via file descriptor(s) maintained by the application.
159 (This functionality can also be obtained by tricks based
160 on the use of
161 .IR /proc/self/fd/ dirfd,
162 but less efficiently.)
163 .SH "SEE ALSO"
164 .BR faccessat (2),
165 .BR fchmodat (2),
166 .BR fchownat (2),
167 .BR fstatat (2),
168 .BR futimesat (2),
169 .BR linkat (2),
170 .BR mkdirat (2),
171 .BR mknodat (2),
172 .BR open (2),
173 .BR readlinkat (2),
174 .BR renameat (2),
175 .BR symlinkat (2),
176 .BR unlinkat (2),
177 .BR utimensat (2),
178 .BR mkfifoat (3),
179 .BR path_resolution (7)