OSDN Git Service

(split) LDP: draft snapshot generated from latest ja.po files.
[linuxjm/LDP_man-pages.git] / draft / man3 / realpath.3
1 .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Rewritten old page, 990824, aeb@cwi.nl
24 .\" 2004-12-14, mtk, added discussion of resolved_path == NULL
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH REALPATH 3 2011\-09\-10 "" "Linux Programmer's Manual"
32 .SH 名前
33 realpath \- 正規化された絶対パス名を返す
34 .SH 書式
35 .nf
36 \fB#include <limits.h>\fP
37 \fB#include <stdlib.h>\fP
38 .sp
39 \fBchar *realpath(const char *\fP\fIpath\fP\fB, char *\fP\fIresolved_path\fP\fB);\fP
40 .fi
41 .sp
42 .in -4n
43 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
44 .in
45 .sp
46 \fBrealpath\fP():
47 .ad l
48 .RS 4
49 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
50 .RE
51 .ad
52 .SH 説明
53 \fBrealpath\fP()  は \fIpath\fP として与えられた NULL 終端された文字列中の すべてのシンボリックリンクを展開し、 \fI/./\fP,
54 \fI/../\fP による参照や余分な \(aq/\(aq を解決して、正規化された絶対パス名を生成する。 得られた絶対パス名は、最大で
55 \fBPATH_MAX\fP バイトの NULL 終端された文字列として、 \fIresolved_path\fP により参照されるバッファに格納される。
56 結果として返るパスの中には、シンボリックリンクや \fI/./\fP, \fI/../\fP といった要素は含まれない。
57
58 .\" Even if we use resolved_path == NULL, then realpath() will still
59 .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
60 .\" bytes -- MTK, Dec 04
61 .\" .SH HISTORY
62 .\" The
63 .\" .BR realpath ()
64 .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
65 \fIresolved_path\fP に NULL が指定されると、 \fBrealpath\fP()  は \fBmalloc\fP(3)
66 を使って解決したパス名を保持するためのバッファを 最大で \fBPATH_MAX\fP バイトまで割り当て、このバッファへのポインタを返す。 呼び出し元は、
67 \fBfree\fP(3)  を使ってこのバッファを解放すべきである。
68 .SH 返り値
69 エラーがなかった場合、 \fBrealpath\fP()  は \fIresolved_path\fP へのポインターを返す。
70
71 それ以外の場合は、ヌル (NULL) ポインターが返り、配列 \fIresolved_path\fP の内容は不定となり、 \fIerrno\fP
72 にエラーの内容を示す値がセットされる。
73 .SH エラー
74 .TP 
75 \fBEACCES\fP
76 パスのディレクトリ部分に、読み出し許可または検索許可が与えられていない。
77 .TP 
78 \fBEINVAL\fP
79 .\" (In libc5 this would just cause a segfault.)
80 \fIpath\fP が NULL である。 (バージョン 2.3 より前の glibc では、 \fIresolved_path\fP が NULL
81 の場合にもこのエラーが返される。)
82 .TP 
83 \fBEIO\fP
84 ファイルシステムを読むときに、I/Oエラーが起こった。
85 .TP 
86 \fBELOOP\fP
87 パス名の変換にあたり、解決すべきシンボリック・リンクの数が多過ぎた。
88 .TP 
89 \fBENAMETOOLONG\fP
90 パス名の一要素の文字数が \fBNAME_MAX\fP を越えている、またはパス名全体の文字数が \fBPATH_MAX\fP を越えている。
91 .TP 
92 \fBENOENT\fP
93 指定されたファイルが存在しない。
94 .TP 
95 \fBENOTDIR\fP
96 パスのディレクトリ要素が、ディレクトリでない。
97 .SH バージョン
98 この関数が Linux に登場したのは libc 4.5.21 である。
99 .SH 準拠
100 4.4BSD, POSIX.1\-2001.
101
102 POSIX.1\-2001 では \fIresolved_path\fP が NULL の場合の動作は実装に依存するとしている。 POSIX.1\-2008
103 では、このマニュアルページに書かれている動作が規定されている。
104 .SH 注意
105 4.4BSD と Solaris では、パス名の長さの上限は (\fI<sys/param.h>\fP の中にある)
106 \fBMAXPATHLEN\fP である。SUSv2 では \fBPATH_MAX\fP と \fBNAME_MAX\fP が規定されており、 これらは
107 \fI<limits.h>\fP で定義されているか、 \fBpathconf\fP(3)
108 関数から得られる。以下のようなソースコードになっていることが多い。
109 .LP
110 .in +4n
111 .nf
112 #ifdef PATH_MAX
113   path_max = PATH_MAX;
114 #else
115   path_max = pathconf(path, _PC_PATH_MAX);
116   if (path_max <= 0)
117          path_max = 4096;
118 #endif
119 .fi
120 .in
121 .LP
122 (バグの章も参照のこと。)
123 .LP
124 4.4BSD、Linux、SUSv2 では、返り値は常に絶対パス名である。 Solaris では、 引き数 \fIpath\fP
125 が相対パスの場合、返り値が相対パスになることがある。 \fBrealpath\fP()  のプロトタイプ宣言は、 libc4 と libc5 では
126 \fI<unistd.h>\fP にあるが、 それ以外の環境ではいずれも \fI<stdlib.h>\fP にある。
127 .SH バグ
128 この関数の POSIX.1\-2001 版は、設計段階から問題がある。 出力バッファ \fIresolved_path\fP
129 の適切なサイズを決定することができないからである。 POSIX.1\-2001 ではバッファ・サイズとして \fBPATH_MAX\fP
130 は十分だとされているが、 \fBPATH_MAX\fP は定義済の定数である必要はなく、 \fBpathconf\fP(3)
131 を使って得られる値であってもよいことになっている。 \fBpathconf\fP(3)  からバッファ・サイズを取得したとしても必ずしも十分ではない。
132 なぜなら、POSIX で警告されているように、 \fBpathconf\fP(3)  の返り値が大き過ぎて適切にメモリを確保することができない
133 かもしれない一方で、 \fBpathconf\fP(3)  は \fBPATH_MAX\fP に制限がないことを示す \-1 を返すかもしれないからである。
134 \fIresolved_path\ ==\ NULL\fP の機能を使うと、この設計上の問題を回避することができる。 この機能は POSIX.1\-2001
135 では標準化されていないが、 POSIX.1\-2008 では標準化されている。
136 .LP
137 libc4 と libc5 の実装はバッファ・オーバーフローの可能性を持っている (libc\-5.4.13 で修正されたが)。したがって、
138 \fBmount\fP(8)  のような set\-user\-ID されるプログラムでは、 この関数相当の関数を自前で持つ必要がある。
139 .SH 関連項目
140 \fBreadlink\fP(2), \fBcanonicalize_file_name\fP(3), \fBgetcwd\fP(3), \fBpathconf\fP(3),
141 \fBsysconf\fP(3)