.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" This manpage is Copyright (C) 2006, Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH OPENAT 2 2012\-05\-04 Linux "Linux Programmer's Manual" .SH 名前 openat \- ディレクトリファイルディスクリプタから相対的な位置にあるファイルをオープンする .SH 書式 .nf \fB#include \fP .sp \fBint openat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB, int \fP\fIflags\fP\fB);\fP \fBint openat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB, int \fP\fIflags\fP\fB, mode_t \fP\fImode\fP\fB);\fP .fi .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBopenat\fP(): .PD 0 .ad l .RS 4 .TP 4 glibc 2.10 以降: _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L .TP glibc 2.10 より前: _ATFILE_SOURCE .RE .ad .PD .SH 説明 \fBopenat\fP() システムコールは、この man ページで説明している違いがある以外は、 \fBopen\fP(2) と全く同じように動作する。 \fIpathname\fP で指定されるパス名が相対パスである場合、 ファイルディスクリプタ \fIdirfd\fP で参照されるディレクトリからの相対パス名として解釈される (\fBopen\fP(2) では、相対パスは呼び出し元プロセスのカレントワーキングディレクトリからの 相対パスとなる)。 \fIpathname\fP が相対パスであり、かつ \fIdirfd\fP が特別な値 \fBAT_FDCWD\fP である場合、 \fIpathname\fP は (\fBopen\fP(2) と同じように) 呼び出し元プロセスの カレントワーキングディレクトリからの相対パス名として解釈される。 \fIpathname\fP が絶対パスである場合、 \fIdirfd\fP は無視される。 .SH 返り値 成功した場合、 \fBopenat\fP() は新しいファイルディスクリプタを返す。 エラーの場合、\-1 が返されて、 \fIerrno\fP にはエラーを示す値が設定される。 .SH エラー \fBopen\fP(2) と同じエラーが \fBopenat\fP() でも起こる。 \fBopenat\fP() では、その他に以下のエラーが起こる: .TP \fBEBADF\fP \fIdirfd\fP が有効なファイルディスクリプタでない。 .TP \fBENOTDIR\fP \fIpathname\fP が相対パスで、かつ \fIdirfd\fP がディレクトリ以外のファイルを参照するファイルディスクリプタである。 .SH バージョン \fBopenat\fP() は Linux カーネル 2.6.16 で追加された。 ライブラリによるサポートは glibc バージョン 2.4 で追加された。 .SH 準拠 .\" The 'at' suffix in Solaris is actually double sensed. It .\" primarily referred to "extended *at*tributes", which are .\" handled by Solaris' O_XATTR flag, but was also intended .\" to refer to the notion of "at a relative location". .\" .\" See the following for a discussion of the inconsistent .\" naming of the *at() functions: .\" http://www.opengroup.org/austin/mailarchives/ag/msg09103.html .\" Subject: RE: The naming of at()s is a difficult matter .\" From: Don Cragun .\" Date: Tue, 14 Feb 2006 14:56:50 -0800 (PST) .\" POSIX.1\-2008. Solaris には、これと同じようなシステムコールが存在する。 .SH 注意 \fBopenat\fP() や "at" が後ろに付いたその他の同様のシステムコールは、 2 つの理由により提供されている。 1 つ目の理由は、 カレントワーキングディレクトリ以外のディレクトリにあるファイル群を \fBopen\fP(2) でオープンするときに起こる可能性がある競合状態 (race condition) を、 \fBopenat\fP() によってアプリケーションが回避できるためである。 これらの競合状態は、 \fBopen\fP(2) に指定されたパスのディレクトリ部分の (/ で区切られた) いくつかの構成要素 (をオープンする処理) が、 \fBopen\fP(2) を並列に呼び出す処理に変換された場合に起こる。 このような競合は、対象ディレクトリのファイルディスクリプタをオープンし、 そのファイルディスクリプタを \fBopenat\fP() の \fIdirfd\fP 引き数に指定することで回避できる。 2 つ目の理由は、 アプリケーションによって管理されるファイルディスクリプタ (群) を使うことで、 \fBopenat\fP() がスレッド毎のいわゆる「カレントワーキングディレクトリ」を実装できるためである。 (この機能は \fI/proc/self/fd/\fPdirfd を使った裏技でも実現できるが、あまり効率的ではない)。 .SH 関連項目 \fBfaccessat\fP(2), \fBfchmodat\fP(2), \fBfchownat\fP(2), \fBfstatat\fP(2), \fBfutimesat\fP(2), \fBlinkat\fP(2), \fBmkdirat\fP(2), \fBmknodat\fP(2), \fBopen\fP(2), \fBreadlinkat\fP(2), \fBrenameat\fP(2), \fBsymlinkat\fP(2), \fBunlinkat\fP(2), \fButimensat\fP(2), \fBmkfifoat\fP(3), \fBpath_resolution\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.41 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。