.\" Copyright (C), 1994, Graeme W. Wilford. (Wilf.) .\" .\" 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. .\" .\" Rewritten old page, 990824, aeb@cwi.nl .\" 2004-12-14, mtk, added discussion of resolved_path == NULL .\" .\" Japanese Version Copyright (c) 1998 SHOJI Yasushi all rights reserved. .\" Translated 1998-03-22, SHOJI Yasushi .\" Updated 1999-03-07, Shouichi Saito .\" Updated 2003-01-17, Akihiro MOTOKI .\" Updated 2005-02-27, Akihiro MOTOKI .\" Updated 2005-09-06, Akihiro MOTOKI .\" Updated 2009-04-24, Akihiro MOTOKI, LDP v3.20 .\" .\"WORD: bounded 制限がない .\" .TH REALPATH 3 2010-09-20 "" "Linux Programmer's Manual" .\"O .SH NAME .\"O realpath \- return the canonicalized absolute pathname .SH 名前 realpath \- 正規化された絶対パス名を返す .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .B #include .sp .BI "char *realpath(const char *" path ", char *" resolved_path ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR realpath (): .ad l .RS 4 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .RE .ad .\"O .SH DESCRIPTION .SH 説明 .\"O .BR realpath () .\"O expands all symbolic links and resolves references .\"O to .\"O .IR "/./" ", " "/../" .\"O and extra \(aq/\(aq .\"O characters in the null-terminated string named by .\"O .I path .\"O to produce a canonicalized absolute pathname. .\"O The resulting pathname is stored as a null-terminated string, .\"O up to a maximum of .\"O .B PATH_MAX .\"O bytes, .\"O in the buffer pointed to by .\"O .IR resolved_path . .BR realpath () は .I path として与えられた NULL 終端された文字列中の すべてのシンボリックリンクを展開し、 .IR "/./" ", " "/../" による参照や余分な \(aq/\(aq を解決して、正規化された絶対パス名を生成する。 得られた絶対パス名は、最大で .B PATH_MAX バイトの NULL 終端された文字列として、 .I resolved_path により参照されるバッファに格納される。 .\"O The resulting path will have no symbolic link, .\"O .I "/./" .\"O or .\"O .I "/../" .\"O components. 結果として返るパスの中には、シンボリックリンクや .IR "/./" ", " "/../" といった要素は含まれない。 .\"O If .\"O .I resolved_path .\"O is specified as NULL, then .\"O .BR realpath () .\"O uses .\"O .BR malloc (3) .\"O to allocate a buffer of up to .\"O .B PATH_MAX .\"O bytes to hold the resolved pathname, .\"O and returns a pointer to this buffer. .\"O The caller should deallocate this buffer using .\"O .BR free (3). .I resolved_path に NULL が指定されると、 .BR realpath () は .BR malloc (3) を使って解決したパス名を保持するためのバッファを 最大で .B PATH_MAX バイトまで割り当て、このバッファへのポインタを返す。 呼び出し元は、 .BR free (3) を使ってこのバッファを解放すべきである。 .\"O .\" Even if we use resolved_path == NULL, then realpath() will still .\"O .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX .\"O .\" bytes -- MTK, Dec 04 .\" resolved_path == NULL を指定した場合でも、解決したパス名の長さが .\" PATH_MAX バイトを超えたときには、realpath() は前と同じく .\" ENAMETOOLONG を返す。-- MTK, Dec 04 .\"O .\" .SH HISTORY .\" .SH 歴史 .\"O .\" The .\"O .\" .BR realpath () .\"O .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry. .\" .BR realpath () .\" 関数は 4.4BSD で初めて登場した (Jan-Simon Pendry により提供された)。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O If there is no error, .\"O .BR realpath () .\"O returns a pointer to the .\"O .IR resolved_path . エラーがなかった場合、 .BR realpath () は .I resolved_path へのポインターを返す。 .\"O Otherwise it returns a NULL pointer, and the contents .\"O of the array .\"O .I resolved_path .\"O are undefined, and .\"O .I errno .\"O is set to indicate the error. それ以外の場合は、ヌル (NULL) ポインターが返り、配列 .I resolved_path の内容は不定となり、 .I errno にエラーの内容を示す値がセットされる。 .\"O .SH ERRORS .SH エラー .TP .B EACCES .\"O Read or search permission was denied for a component of the path prefix. パスのディレクトリ部分に、読み出し許可または検索許可が与えられていない。 .TP .B EINVAL .\"O Either .\"O .I path .\"O or .\"O .I resolved_path .\"O is NULL. .\"O (In libc5 this would just cause a segfault.) .\"O But, see NOTES below. .I path か .I resolved_path のいずれかが NULL である。 (libc5 では、このような場合 segfault を起こすだけであろう) 但し、下記の「注意」の節を参照のこと。 .TP .B EIO .\"O An I/O error occurred while reading from the file system. ファイルシステムを読むときに、I/Oエラーが起こった。 .TP .B ELOOP .\"O Too many symbolic links were encountered in translating the pathname. パス名の変換にあたり、解決すべきシンボリック・リンクの数が多過ぎた。 .TP .B ENAMETOOLONG .\"O A component of a pathname exceeded .\"O .B NAME_MAX .\"O characters, or an entire pathname exceeded .\"O .B PATH_MAX .\"O characters. パス名の一要素の文字数が .B NAME_MAX を越えている、またはパス名全体の文字数が .B PATH_MAX を越えている。 .TP .B ENOENT .\"O The named file does not exist. 指定されたファイルが存在しない。 .TP .B ENOTDIR .\"O A component of the path prefix is not a directory. パスのディレクトリ要素が、ディレクトリでない。 .\"O .SH VERSIONS .SH バージョン .\"O On Linux this function appeared in libc 4.5.21. この関数が Linux に登場したのは libc 4.5.21 である。 .\"O .SH "CONFORMING TO" .SH 準拠 4.4BSD, POSIX.1-2001. .\"O POSIX.1-2001 says that the behavior if .\"O .I resolved_path .\"O is NULL is implementation-defined. .\"O POSIX.1-2008 specifies the behavior described in this page. POSIX.1-2001 では .I resolved_path が NULL の場合の動作は実装に依存するとしている。 POSIX.1-2008 では、このマニュアルページに書かれている動作が規定されている。 .\"O .SH NOTES .SH 注意 .\"O In 4.4BSD and Solaris the limit on the pathname length is .\"O .B MAXPATHLEN .\"O (found in \fI\fP). .\"O SUSv2 prescribes .\"O .B PATH_MAX .\"O and .\"O .BR NAME_MAX , .\"O as found in \fI\fP or provided by the .\"O .BR pathconf (3) .\"O function. .\"O A typical source fragment would be .\"O .LP .\"O .in +4n .\"O .nf .\"O #ifdef PATH_MAX .\"O path_max = PATH_MAX; .\"O #else .\"O path_max = pathconf(path, _PC_PATH_MAX); .\"O if (path_max <= 0) .\"O path_max = 4096; .\"O #endif .\"O .fi .\"O .in 4.4BSD と Solaris では、パス名の長さの上限は (\fI\fP の中にある) .B MAXPATHLEN である。SUSv2 では .B PATH_MAX と .B NAME_MAX が規定されており、 これらは \fI\fP で定義されているか、 .BR pathconf (3) 関数から得られる。以下のようなソースコードになっていることが多い。 .LP .in +4n .nf #ifdef PATH_MAX path_max = PATH_MAX; #else path_max = pathconf(path, _PC_PATH_MAX); if (path_max <= 0) path_max = 4096; #endif .fi .in .LP .\"O (But see the BUGS section.) (バグの章も参照のこと。) .LP .\"O The 4.4BSD, Linux and SUSv2 versions always return an absolute .\"O pathname. .\"O Solaris may return a relative pathname when the .\"O .I path .\"O argument is relative. 4.4BSD、Linux、SUSv2 では、返り値は常に絶対パス名である。 Solaris では、 引き数 .I path が相対パスの場合、返り値が相対パスになることがある。 .\"O The prototype of .\"O .BR realpath () .\"O is given in \fI\fP in libc4 and libc5, .\"O but in \fI\fP everywhere else. .BR realpath () のプロトタイプ宣言は、 libc4 と libc5 では \fI\fP にあるが、 それ以外の環境ではいずれも \fI\fP にある。 .\"O .SH BUGS .SH バグ .\"O The POSIX.1-2001 standard version of this function is broken by design, .\"O since it is impossible to determine a suitable size for the output buffer, .\"O .IR resolved_path . .\"O According to POSIX.1-2001 a buffer of size .\"O .B PATH_MAX .\"O suffices, but .\"O .B PATH_MAX .\"O need not be a defined constant, and may have to be obtained using .\"O .BR pathconf (3). この関数の POSIX.1-2001 版は、設計段階から問題がある。 出力バッファ .I resolved_path の適切なサイズを決定することができないからである。 POSIX.1-2001 ではバッファ・サイズとして .B PATH_MAX は十分だとされているが、 .B PATH_MAX は定義済の定数である必要はなく、 .BR pathconf (3) を使って得られる値であってもよいことになっている。 .\"O And asking .\"O .BR pathconf (3) .\"O does not really help, since, on the one hand POSIX warns that .\"O the result of .\"O .BR pathconf (3) .\"O may be huge and unsuitable for mallocing memory, .\"O and on the other hand .\"O .BR pathconf (3) .\"O may return \-1 to signify that .\"O .B PATH_MAX .\"O is not bounded. .BR pathconf (3) からバッファ・サイズを取得したとしても必ずしも十分ではない。 なぜなら、POSIX で警告されているように、 .BR pathconf (3) の返り値が大き過ぎて適切にメモリを確保することができない かもしれない一方で、 .BR pathconf (3) は .B PATH_MAX に制限がないことを示す \-1 を返すかもしれないからである。 .\"O The .\"O .I "resolved_path\ ==\ NULL" .\"O feature, not standardized in POSIX.1-2001, .\"O but standardized in POSIX.1-2008, allows this design problem to be avoided. .I "resolved_path\ ==\ NULL" の機能を使うと、この設計上の問題を回避することができる。 この機能は POSIX.1-2001 では標準化されていないが、 POSIX.1-2008 では標準化されている。 .LP .\"O The libc4 and libc5 implementation contains a buffer overflow .\"O (fixed in libc-5.4.13). .\"O Thus, set-user-ID programs like .\"O .BR mount (8) .\"O need a private version. libc4 と libc5 の実装はバッファ・オーバーフローの可能性を持っている (libc-5.4.13 で修正されたが)。したがって、 .BR mount (8) のような set-user-ID されるプログラムでは、 この関数相当の関数を自前で持つ必要がある。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR readlink (2), .BR canonicalize_file_name (3), .BR getcwd (3), .BR pathconf (3), .BR sysconf (3)