1 .\" Copyright (C), 1994, Graeme W. Wilford. (Wilf.)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Rewritten old page, 990824, aeb@cwi.nl
24 .\" 2004-12-14, mtk, added discussion of resolved_path == NULL
26 .\" Japanese Version Copyright (c) 1998 SHOJI Yasushi all rights reserved.
27 .\" Translated 1998-03-22, SHOJI Yasushi <yashi@yashi.com>
28 .\" Updated 1999-03-07, Shouichi Saito
29 .\" Updated 2003-01-17, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
30 .\" Updated 2005-02-27, Akihiro MOTOKI
31 .\" Updated 2005-09-06, Akihiro MOTOKI
32 .\" Updated 2009-04-24, Akihiro MOTOKI, LDP v3.20
34 .\"WORD: bounded 制限がない
36 .TH REALPATH 3 2011-09-10 "" "Linux Programmer's Manual"
38 .\"O realpath \- return the canonicalized absolute pathname
40 realpath \- 正規化された絶対パス名を返す
44 .B #include <limits.h>
45 .B #include <stdlib.h>
47 .BI "char *realpath(const char *" path ", char *" resolved_path );
51 .\"O Feature Test Macro Requirements for glibc (see
52 .\"O .BR feature_test_macros (7)):
54 .RB ( feature_test_macros (7)
61 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
62 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
68 .\"O expands all symbolic links and resolves references
70 .\"O .IR "/./" ", " "/../"
71 .\"O and extra \(aq/\(aq
72 .\"O characters in the null-terminated string named by
74 .\"O to produce a canonicalized absolute pathname.
75 .\"O The resulting pathname is stored as a null-terminated string,
76 .\"O up to a maximum of
79 .\"O in the buffer pointed to by
80 .\"O .IR resolved_path .
84 として与えられた NULL 終端された文字列中の
88 を解決して、正規化された絶対パス名を生成する。
91 バイトの NULL 終端された文字列として、
94 .\"O The resulting path will have no symbolic link,
99 結果として返るパスの中には、シンボリックリンクや
100 .IR "/./" ", " "/../"
103 .\"O .I resolved_path
104 .\"O is specified as NULL, then
108 .\"O to allocate a buffer of up to
110 .\"O bytes to hold the resolved pathname,
111 .\"O and returns a pointer to this buffer.
112 .\"O The caller should deallocate this buffer using
119 を使って解決したパス名を保持するためのバッファを
122 バイトまで割り当て、このバッファへのポインタを返す。
126 .\"O .\" Even if we use resolved_path == NULL, then realpath() will still
127 .\"O .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
128 .\"O .\" bytes -- MTK, Dec 04
129 .\" resolved_path == NULL を指定した場合でも、解決したパス名の長さが
130 .\" PATH_MAX バイトを超えたときには、realpath() は前と同じく
131 .\" ENAMETOOLONG を返す。-- MTK, Dec 04
135 .\"O .\" .BR realpath ()
136 .\"O .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
138 .\" 関数は 4.4BSD で初めて登場した (Jan-Simon Pendry により提供された)。
139 .\"O .SH "RETURN VALUE"
141 .\"O If there is no error,
143 .\"O returns a pointer to the
144 .\"O .IR resolved_path .
151 .\"O Otherwise it returns a NULL pointer, and the contents
153 .\"O .I resolved_path
154 .\"O are undefined, and
156 .\"O is set to indicate the error.
157 それ以外の場合は、ヌル (NULL) ポインターが返り、配列
166 .\"O Read or search permission was denied for a component of the path prefix.
167 パスのディレクトリ部分に、読み出し許可または検索許可が与えられていない。
172 .\"O .\" (In libc5 this would just cause a segfault.)
173 .\"O (In glibc versions before 2.3,
174 .\"O this error is also returned if
175 .\"O .IR resolved_path
179 .\" (libc5 では、このような場合 segfault を起こすだけであろう)
180 (バージョン 2.3 より前の glibc では、
182 が NULL の場合にもこのエラーが返される。)
185 .\"O An I/O error occurred while reading from the file system.
186 ファイルシステムを読むときに、I/Oエラーが起こった。
189 .\"O Too many symbolic links were encountered in translating the pathname.
190 パス名の変換にあたり、解決すべきシンボリック・リンクの数が多過ぎた。
193 .\"O A component of a pathname exceeded
195 .\"O characters, or an entire pathname exceeded
205 .\"O The named file does not exist.
209 .\"O A component of the path prefix is not a directory.
210 パスのディレクトリ要素が、ディレクトリでない。
213 .\"O On Linux this function appeared in libc 4.5.21.
214 この関数が Linux に登場したのは libc 4.5.21 である。
215 .\"O .SH "CONFORMING TO"
217 4.4BSD, POSIX.1-2001.
219 .\"O POSIX.1-2001 says that the behavior if
220 .\"O .I resolved_path
221 .\"O is NULL is implementation-defined.
222 .\"O POSIX.1-2008 specifies the behavior described in this page.
225 が NULL の場合の動作は実装に依存するとしている。
226 POSIX.1-2008 では、このマニュアルページに書かれている動作が規定されている。
229 .\"O In 4.4BSD and Solaris the limit on the pathname length is
231 .\"O (found in \fI<sys/param.h>\fP).
232 .\"O SUSv2 prescribes
236 .\"O as found in \fI<limits.h>\fP or provided by the
237 .\"O .BR pathconf (3)
239 .\"O A typical source fragment would be
244 .\"O path_max = PATH_MAX;
246 .\"O path_max = pathconf(path, _PC_PATH_MAX);
247 .\"O if (path_max <= 0)
248 .\"O path_max = 4096;
252 4.4BSD と Solaris では、パス名の長さの上限は
253 (\fI<sys/param.h>\fP の中にある)
260 これらは \fI<limits.h>\fP で定義されているか、
262 関数から得られる。以下のようなソースコードになっていることが多い。
269 path_max = pathconf(path, _PC_PATH_MAX);
276 .\"O (But see the BUGS section.)
279 .\"O The 4.4BSD, Linux and SUSv2 versions always return an absolute
281 .\"O Solaris may return a relative pathname when the
283 .\"O argument is relative.
284 4.4BSD、Linux、SUSv2 では、返り値は常に絶対パス名である。
288 が相対パスの場合、返り値が相対パスになることがある。
289 .\"O The prototype of
291 .\"O is given in \fI<unistd.h>\fP in libc4 and libc5,
292 .\"O but in \fI<stdlib.h>\fP everywhere else.
295 libc4 と libc5 では \fI<unistd.h>\fP にあるが、
296 それ以外の環境ではいずれも \fI<stdlib.h>\fP にある。
299 .\"O The POSIX.1-2001 standard version of this function is broken by design,
300 .\"O since it is impossible to determine a suitable size for the output buffer,
301 .\"O .IR resolved_path .
302 .\"O According to POSIX.1-2001 a buffer of size
306 .\"O need not be a defined constant, and may have to be obtained using
307 .\"O .BR pathconf (3).
308 この関数の POSIX.1-2001 版は、設計段階から問題がある。
311 の適切なサイズを決定することができないからである。
312 POSIX.1-2001 ではバッファ・サイズとして
318 を使って得られる値であってもよいことになっている。
320 .\"O .BR pathconf (3)
321 .\"O does not really help, since, on the one hand POSIX warns that
323 .\"O .BR pathconf (3)
324 .\"O may be huge and unsuitable for mallocing memory,
325 .\"O and on the other hand
326 .\"O .BR pathconf (3)
327 .\"O may return \-1 to signify that
331 からバッファ・サイズを取得したとしても必ずしも十分ではない。
332 なぜなら、POSIX で警告されているように、
334 の返り値が大き過ぎて適切にメモリを確保することができない
339 に制限がないことを示す \-1 を返すかもしれないからである。
341 .\"O .I "resolved_path\ ==\ NULL"
342 .\"O feature, not standardized in POSIX.1-2001,
343 .\"O but standardized in POSIX.1-2008, allows this design problem to be avoided.
344 .I "resolved_path\ ==\ NULL"
345 の機能を使うと、この設計上の問題を回避することができる。
346 この機能は POSIX.1-2001 では標準化されていないが、
347 POSIX.1-2008 では標準化されている。
349 .\"O The libc4 and libc5 implementation contains a buffer overflow
350 .\"O (fixed in libc-5.4.13).
351 .\"O Thus, set-user-ID programs like
353 .\"O need a private version.
354 libc4 と libc5 の実装はバッファ・オーバーフローの可能性を持っている
355 (libc-5.4.13 で修正されたが)。したがって、
357 のような set-user-ID されるプログラムでは、
358 この関数相当の関数を自前で持つ必要がある。
362 .BR canonicalize_file_name (3),