.\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl) .\" .\" %%%LICENSE_START(VERBATIM) .\" 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. .\" %%%LICENSE_END .\" .\" Rewritten old page, 990824, aeb@cwi.nl .\" 2004-12-14, mtk, added discussion of resolved_path == NULL .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" 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 .\" Updated 2012-05-29, Akihiro MOTOKI .\" Updated 2013-03-27, Akihiro MOTOKI .\" .TH REALPATH 3 2013\-03\-15 "" "Linux Programmer's Manual" .SH 名前 realpath \- 正規化された絶対パス名を返す .SH 書式 .nf \fB#include \fP \fB#include \fP .sp \fBchar *realpath(const char *\fP\fIpath\fP\fB, char *\fP\fIresolved_path\fP\fB);\fP .fi .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBrealpath\fP(): .ad l .RS 4 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .RE .ad .SH 説明 \fBrealpath\fP() は \fIpath\fP として与えられたヌル終端された文字列中の すべてのシンボリックリンクを展開し、 \fI/./\fP, \fI/../\fP による参照や余分な \(aq/\(aq を解決して、正規化された絶対パス名を生成する。 得られた絶対パス名は、最大で \fBPATH_MAX\fP バイトのヌル終端された文字列として、 \fIresolved_path\fP により参照されるバッファに格納される。 結果として返るパスの中には、シンボリックリンクや \fI/./\fP, \fI/../\fP といった要素は含まれない。 .\" Even if we use resolved_path == NULL, then realpath() will still .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX .\" bytes -- MTK, Dec 04 .\" .SH HISTORY .\" The .\" .BR realpath () .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry. \fIresolved_path\fP に NULL が指定されると、 \fBrealpath\fP() は \fBmalloc\fP(3) を使って解決したパス名を保持するためのバッファを 最大で \fBPATH_MAX\fP バイトまで割り当て、このバッファへのポインタを返す。 呼び出し元は、 \fBfree\fP(3) を使ってこのバッファを解放すべきである。 .SH 返り値 エラーがなかった場合、 \fBrealpath\fP() は \fIresolved_path\fP へのポインターを返す。 それ以外の場合は NULL が返り、配列 \fIresolved_path\fP の内容は不定となり、 \fIerrno\fP にエラーの内容を示す値がセットされる。 .SH エラー .TP \fBEACCES\fP パスのディレクトリ部分に、読み出し許可または検索許可が与えられていない。 .TP \fBEINVAL\fP .\" (In libc5 this would just cause a segfault.) \fIpath\fP が NULL である。 (バージョン 2.3 より前の glibc では、 \fIresolved_path\fP が NULL の場合にもこのエラーが返される。) .TP \fBEIO\fP ファイルシステムを読むときに、I/Oエラーが起こった。 .TP \fBELOOP\fP パス名の変換にあたり、解決すべきシンボリック・リンクの数が多過ぎた。 .TP \fBENAMETOOLONG\fP パス名の一要素の文字数が \fBNAME_MAX\fP を越えている、またはパス名全体の文字数が \fBPATH_MAX\fP を越えている。 .TP \fBENOENT\fP 指定されたファイルが存在しない。 .TP \fBENOTDIR\fP パスのディレクトリ要素が、ディレクトリでない。 .SH バージョン Linux では、この関数が登場したのは libc 4.5.21 である。 .SH 準拠 4.4BSD, POSIX.1\-2001. POSIX.1\-2001 では \fIresolved_path\fP が NULL の場合の動作は実装に依存するとしている。 POSIX.1\-2008 では、このマニュアルページに書かれている動作が規定されている。 .SH 注意 4.4BSD と Solaris では、パス名の長さの上限は (\fI\fP の中にある) \fBMAXPATHLEN\fP である。SUSv2 では \fBPATH_MAX\fP と \fBNAME_MAX\fP が規定されており、 これらは \fI\fP で定義されているか、 \fBpathconf\fP(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 (バグの章も参照のこと。) .LP .\" 2012-05-05, According to Casper Dik, the statement about .\" Solaris was not true at least as far back as 1997, and .\" may never have been true. .\" .\" The 4.4BSD, Linux and SUSv2 versions always return an absolute .\" pathname. .\" Solaris may return a relative pathname when the .\" .I path .\" argument is relative. \fBrealpath\fP() のプロトタイプ宣言は、 libc4 と libc5 では \fI\fP にあるが、それ以外の環境ではいずれも \fI\fP にある。 .SS "GNU による拡張" 呼び出しが \fBEACCES\fP か \fBENOENT\fP で失敗し \fIresolved_path\fP が NULL でない場合、読むことができない、もしくは存在しない \fIpath\fP のディレクトリ要素 (prefix) が \fIresolved_path\fP で返される。 .SH バグ この関数の POSIX.1\-2001 版は、設計段階から問題がある。 出力バッファ \fIresolved_path\fP の適切なサイズを決定することができないからである。 POSIX.1\-2001 ではバッファ・サイズとして \fBPATH_MAX\fP は十分だとされているが、 \fBPATH_MAX\fP は定義済の定数である必要はなく、 \fBpathconf\fP(3) を使って得られる値であってもよいことになっている。 \fBpathconf\fP(3) からバッファ・サイズを取得したとしても必ずしも十分ではない。 なぜなら、POSIX で警告されているように、 \fBpathconf\fP(3) の返り値が大き過ぎて適切にメモリを確保することができない かもしれない一方で、 \fBpathconf\fP(3) は \fBPATH_MAX\fP に制限がないことを示す \-1 を返すかもしれないからである。 \fIresolved_path\ ==\ NULL\fP の機能を使うと、この設計上の問題を回避することができる。 この機能は POSIX.1\-2001 では標準化されていないが、 POSIX.1\-2008 では標準化されている。 .LP libc4 と libc5 の実装はバッファ・オーバーフローの可能性を持っていた (libc\-5.4.13 で修正されたが)。したがって、 \fBmount\fP(8) のような set\-user\-ID されるプログラムでは、この関数相当の関数を自前で持つ必要があった。 .SH 関連項目 \fBreadlink\fP(2), \fBcanonicalize_file_name\fP(3), \fBgetcwd\fP(3), \fBpathconf\fP(3), \fBsysconf\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。