OSDN Git Service

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