OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / release / 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 .\" Japanese Version Copyright (c) 2006 Yuichi SATO
26 .\"         all rights reserved.
27 .\" Translated 2006-09-27 by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v2.39
28 .\"
29 .TH OPENAT 2 2009-12-13 "Linux" "Linux Programmer's Manual"
30 .SH 名前
31 openat \- ディレクトリファイルディスクリプタから相対的な位置にあるファイルをオープンする
32 .SH 書式
33 .nf
34 .B #include <fcntl.h>
35 .sp
36 .BI "int openat(int " dirfd ", const char *" pathname ", int " flags );
37 .BI "int openat(int " dirfd ", const char *" pathname ", int " flags \
38 ", mode_t " mode );
39 .fi
40 .sp
41 .in -4n
42 glibc 向けの機能検査マクロの要件
43 .RB ( feature_test_macros (7)
44 参照):
45 .in
46 .sp
47 .BR openat ():
48 .PD 0
49 .ad l
50 .RS 4
51 .TP 4
52 glibc 2.10 以降:
53 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
54 .TP
55 glibc 2.10 より前:
56 _ATFILE_SOURCE
57 .RE
58 .ad
59 .PD
60 .SH 説明
61 .BR openat ()
62 システムコールは、この man ページで説明している違いがある以外は、
63 .BR open (2)
64 と全く同じように動作する。
65
66 .I pathname
67 で指定されるパス名が相対パスである場合、
68 ファイルディスクリプタ
69 .I dirfd
70 で参照されるディレクトリからの相対パス名として解釈される
71 .RB ( open (2)
72 では、相対パスは呼び出し元プロセスのカレントワーキングディレクトリからの
73 相対パスとなる)。
74
75 .I pathname
76 が相対パスであり、かつ
77 .I dirfd
78 が特別な値
79 .B AT_FDCWD
80 である場合、
81 .I pathname
82
83 .RB ( open (2)
84 と同じように) 呼び出し元プロセスの
85 カレントワーキングディレクトリからの相対パス名として解釈される。
86
87 .I pathname
88 が絶対パスである場合、
89 .I dirfd
90 は無視される。
91 .SH 返り値
92 成功した場合、
93 .BR openat ()
94 は新しいファイルディスクリプタを返す。
95 エラーの場合、\-1 が返されて、
96 .I errno
97 にはエラーを示す値が設定される。
98 .SH エラー
99 .BR open (2)
100 と同じエラーが
101 .BR openat ()
102 でも起こる。
103 .BR openat ()
104 では、その他に以下のエラーが起こる:
105 .TP
106 .B EBADF
107 .I dirfd
108 が有効なファイルディスクリプタでない。
109 .TP
110 .B ENOTDIR
111 .I pathname
112 が相対パスで、かつ
113 .I dirfd
114 がディレクトリ以外のファイルを参照するファイルディスクリプタである。
115 .SH バージョン
116 .BR openat ()
117 は Linux カーネル 2.6.16 で追加された。
118 .SH 準拠
119 POSIX.1-2008.
120 Solaris には、これと同じようなシステムコールが存在する。
121 .\" The 'at' suffix in Solaris is actually double sensed.  It
122 .\" primarily referred to "extended *at*tributes", which are
123 .\" handled by Solaris' O_XATTR flag, but was also intended
124 .\" to refer to the notion of "at a relative location".
125 .\"
126 .\" See the following for a discussion of the inconsistent
127 .\" naming of the *at() functions:
128 .\" http://www.opengroup.org/austin/mailarchives/ag/msg09103.html
129 .\" Subject:    RE: The naming of at()s is a difficult matter
130 .\" From:       Don Cragun
131 .\" Date:       Tue, 14 Feb 2006 14:56:50 -0800 (PST)
132 .\"
133 .SH 注意
134 .BR openat ()
135 や "at" が後ろに付いたその他の同様のシステムコールは、
136 2 つの理由により提供されている。
137
138 1 つ目の理由は、
139 カレントワーキングディレクトリ以外のディレクトリにあるファイル群を
140 .BR open (2)
141 でオープンするときに起こる可能性がある競合状態 (race condition) を、
142 .BR openat ()
143 によってアプリケーションが回避できるためである。
144 これらの競合状態は、
145 .BR open (2)
146 に指定されたパスのディレクトリ部分の
147 (/ で区切られた) いくつかの構成要素 (をオープンする処理) が、
148 .BR open (2)
149 を並列に呼び出す処理に変換された場合に起こる。
150 このような競合は、対象ディレクトリのファイルディスクリプタをオープンし、
151 そのファイルディスクリプタを
152 .BR openat ()
153
154 .I dirfd
155 引き数に指定することで回避できる。
156
157 2 つ目の理由は、
158 アプリケーションによって管理されるファイルディスクリプタ (群) を使うことで、
159 .BR openat ()
160 がスレッド毎のいわゆる「カレントワーキングディレクトリ」を実装できるためである。
161 (この機能は
162 .IR /proc/self/fd/ dirfd
163 を使った裏技でも実現できるが、あまり効率的ではない)。
164 .SH 関連項目
165 .BR faccessat (2),
166 .BR fchmodat (2),
167 .BR fchownat (2),
168 .BR fstatat (2),
169 .BR futimesat (2),
170 .BR linkat (2),
171 .BR mkdirat (2),
172 .BR mknodat (2),
173 .BR open (2),
174 .BR readlinkat (2),
175 .BR renameat (2),
176 .BR symlinkat (2),
177 .BR unlinkat (2),
178 .BR utimensat (2),
179 .BR mkfifoat (3),
180 .BR path_resolution (7)