1 .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Rewritten old page, 990824, aeb@cwi.nl
26 .\" 2004-12-14, mtk, added discussion of resolved_path == NULL
28 .\"*******************************************************************
30 .\" This file was generated with po4a. Translate the source file.
32 .\"*******************************************************************
33 .TH REALPATH 3 2013\-03\-15 "" "Linux Programmer's Manual"
35 realpath \- 正規化された絶対パス名を返す
38 \fB#include <limits.h>\fP
39 \fB#include <stdlib.h>\fP
41 \fBchar *realpath(const char *\fP\fIpath\fP\fB, char *\fP\fIresolved_path\fP\fB);\fP
45 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
51 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
55 \fBrealpath\fP() は \fIpath\fP として与えられた NULL 終端された文字列中の すべてのシンボリックリンクを展開し、 \fI/./\fP,
56 \fI/../\fP による参照や余分な \(aq/\(aq を解決して、正規化された絶対パス名を生成する。 得られた絶対パス名は、最大で
57 \fBPATH_MAX\fP バイトの NULL 終端された文字列として、 \fIresolved_path\fP により参照されるバッファに格納される。
58 結果として返るパスの中には、シンボリックリンクや \fI/./\fP, \fI/../\fP といった要素は含まれない。
60 .\" Even if we use resolved_path == NULL, then realpath() will still
61 .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
62 .\" bytes -- MTK, Dec 04
66 .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
67 \fIresolved_path\fP に NULL が指定されると、 \fBrealpath\fP() は \fBmalloc\fP(3)
68 を使って解決したパス名を保持するためのバッファを 最大で \fBPATH_MAX\fP バイトまで割り当て、このバッファへのポインタを返す。 呼び出し元は、
69 \fBfree\fP(3) を使ってこのバッファを解放すべきである。
71 エラーがなかった場合、 \fBrealpath\fP() は \fIresolved_path\fP へのポインターを返す。
73 Otherwise, it returns a NULL pointer, the contents of the array
74 \fIresolved_path\fP are undefined, and \fIerrno\fP is set to indicate the error.
78 パスのディレクトリ部分に、読み出し許可または検索許可が与えられていない。
81 .\" (In libc5 this would just cause a segfault.)
82 \fIpath\fP が NULL である。 (バージョン 2.3 より前の glibc では、 \fIresolved_path\fP が NULL
86 ファイルシステムを読むときに、I/Oエラーが起こった。
89 パス名の変換にあたり、解決すべきシンボリック・リンクの数が多過ぎた。
92 パス名の一要素の文字数が \fBNAME_MAX\fP を越えている、またはパス名全体の文字数が \fBPATH_MAX\fP を越えている。
98 パスのディレクトリ要素が、ディレクトリでない。
100 On Linux, this function appeared in libc 4.5.21.
102 4.4BSD, POSIX.1\-2001.
104 POSIX.1\-2001 では \fIresolved_path\fP が NULL の場合の動作は実装に依存するとしている。 POSIX.1\-2008
105 では、このマニュアルページに書かれている動作が規定されている。
107 In 4.4BSD and Solaris, the limit on the pathname length is \fBMAXPATHLEN\fP
108 (found in \fI<sys/param.h>\fP). SUSv2 prescribes \fBPATH_MAX\fP and
109 \fBNAME_MAX\fP, as found in \fI<limits.h>\fP or provided by the
110 \fBpathconf\fP(3) function. A typical source fragment would be
117 path_max = pathconf(path, _PC_PATH_MAX);
126 .\" 2012-05-05, According to Casper Dik, the statement about
127 .\" Solaris was not true at least as far back as 1997, and
128 .\" may never have been true.
130 .\" The 4.4BSD, Linux and SUSv2 versions always return an absolute
132 .\" Solaris may return a relative pathname when the
134 .\" argument is relative.
135 \fBrealpath\fP() のプロトタイプ宣言は、 libc4 と libc5 では
136 \fI<unistd.h>\fP にあるが、それ以外の環境ではいずれも
137 \fI<stdlib.h>\fP にある。
139 If the call fails with either \fBEACCES\fP or \fBENOENT\fP and \fIresolved_path\fP is
140 not NULL, then the prefix of \fIpath\fP that is not readable or does not exist
141 is returned in \fIresolved_path\fP.
143 この関数の POSIX.1\-2001 版は、設計段階から問題がある。 出力バッファ \fIresolved_path\fP
144 の適切なサイズを決定することができないからである。 POSIX.1\-2001 ではバッファ・サイズとして \fBPATH_MAX\fP
145 は十分だとされているが、 \fBPATH_MAX\fP は定義済の定数である必要はなく、 \fBpathconf\fP(3)
146 を使って得られる値であってもよいことになっている。 \fBpathconf\fP(3) からバッファ・サイズを取得したとしても必ずしも十分ではない。
147 なぜなら、POSIX で警告されているように、 \fBpathconf\fP(3) の返り値が大き過ぎて適切にメモリを確保することができない
148 かもしれない一方で、 \fBpathconf\fP(3) は \fBPATH_MAX\fP に制限がないことを示す \-1 を返すかもしれないからである。
149 \fIresolved_path\ ==\ NULL\fP の機能を使うと、この設計上の問題を回避することができる。 この機能は POSIX.1\-2001
150 では標準化されていないが、 POSIX.1\-2008 では標準化されている。
152 The libc4 and libc5 implementation contained a buffer overflow (fixed in
153 libc\-5.4.13). Thus, set\-user\-ID programs like \fBmount\fP(8) needed a private
156 \fBreadlink\fP(2), \fBcanonicalize_file_name\fP(3), \fBgetcwd\fP(3), \fBpathconf\fP(3),
159 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
160 である。プロジェクトの説明とバグ報告に関する情報は
161 http://www.kernel.org/doc/man\-pages/ に書かれている。