OSDN Git Service

(split) LDP: Update release pages
[linuxjm/LDP_man-pages.git] / release / man3 / getcwd.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified Wed Jul 21 22:35:42 1993 by Rik Faith (faith@cs.unc.edu)
26 .\" Modified 18 Mar 1996 by Martin Schulze (joey@infodrom.north.de):
27 .\"   Corrected description of getwd().
28 .\" Modified Sat Aug 21 12:32:12 MET 1999 by aeb - applied fix by aj
29 .\" Modified Mon Dec 11 13:32:51 MET 2000 by aeb
30 .\" Modified Thu Apr 22 03:49:15 CEST 2002 by Roger Luethi <rl@hellgate.ch>
31 .\"
32 .\"*******************************************************************
33 .\"
34 .\" This file was generated with po4a. Translate the source file.
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" Japanese Version Copyright (c) 1997 IMAMURA Nobutaka
39 .\"         all rights reserved.
40 .\" Translated Fri Feb 14 12:40:22 JST 1997
41 .\"         by IMAMURA Nobutaka <imamura@spp.hpc.fujitsu.co.jp>
42 .\" Modified Thu Dec 8 05:08:44 JST 1999
43 .\"         by Kentaro Shirakata <argrath@yo.rim.or.jp>
44 .\" Modified Sun Mar 12 21:08:44 JST 2000
45 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
46 .\" Updated 2001-01-29 by Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2002-03-23 by Kentaro Shirakata <argrath@ub32.org>
48 .\" Updated 2002-10-17 by Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated 2007-01-01 by Kentaro Shirakata <argrath@ub32.org>
50 .\" Updated 2008-08-21, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.07
51 .\"
52 .TH GETCWD 3 2010\-09\-20 GNU "Linux Programmer's Manual"
53 .SH 名前
54 getcwd, getwd, get_current_dir_name \- カレントワーキングディレクトリ名の取得
55 .SH 書式
56 .nf
57 \fB#include <unistd.h>\fP
58 .sp
59 \fBchar *getcwd(char *\fP\fIbuf\fP\fB, size_t \fP\fIsize\fP\fB);\fP
60 .sp
61 \fBchar *getwd(char *\fP\fIbuf\fP\fB);\fP
62 .sp
63 \fBchar *get_current_dir_name(void);\fP
64 .fi
65 .sp
66 .in -4n
67 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
68 .sp
69 .in
70 \fBget_current_dir_name\fP():
71 .RS
72 _GNU_SOURCE
73 .RE
74 .sp
75 \fBgetwd\fP():
76 .ad l
77 .RS 4
78 .PD 0
79 .TP  4
80 glibc 2.12 以降:
81 .nf
82 _BSD_SOURCE ||
83     (_XOPEN_SOURCE\ >=\ 500 ||
84         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
85     !(_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
86 .TP  4
87 .fi
88 glibc 2.12 より前: _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
89 .PD
90 .RE
91 .ad b
92 .SH 説明
93 これらの関数は、呼び出したプロセスのカレントワーキングディレクトリの 絶対パス名 (absolute pathname) が入った文字列を返す。
94 返される文字列は NULL で終端される。 パス名は関数の結果として返され、引数 \fIbuf\fP がある場合は \fIbuf\fP 経由でも返される。
95
96 \fBgetcwd\fP()  関数はカレントワーキングディレクトリの絶対パス名を \fIbuf\fP で示された \fIsize\fP 長の配列にコピーする。
97 .PP
98 終端の NULL バイトも含めた、カレントワーキングディレクトリの 絶対パス名の長さが \fIsize\fP バイトを超えている場合は、返り値として NULL
99 が返り \fIerrno\fP に \fBERANGE\fP がセットされる。 アプリケーションはこのエラーをチェックし、
100 必要に応じてより長いバッファを用意すべきである。
101 .PP
102 POSIX.1\-2001 標準の拡張として、 Linux (libc4, libc5, glibc) では \fIbuf\fP が NULL の場合、
103 \fBgetcwd\fP()  は必要なバッファを \fBmalloc\fP(3)  を用いて動的に割り当てる。 この場合、 \fIsize\fP が 0
104 の場合を除き、バッファの長さは \fIsize\fP となる。 \fIsize\fP が 0 の場合には必要な大きさが確保される。 呼び出し側で、返されたバッファを
105 \fBfree\fP(3)  すべきである。
106
107 \fBget_current_dir_name\fP()  はカレントワーキングディレクトリの絶対パス名を収めるのに 十分な大きさの配列を
108 \fBmalloc\fP(3)  で獲得する。環境変数 \fBPWD\fP が設定されておりその値が正しければ、その値が返される。 呼び出し側で、返されたバッファを
109 \fBfree\fP(3)  すべきである。
110
111 \fBgetwd\fP()  は \fBmalloc\fP(3)  によるメモリ獲得を一切行なわない。 \fIbuf\fP 引数は少なくとも \fBPATH_MAX\fP
112 バイトの長さを持つ配列へのポインタである必要がある。 終端の NULL バイトも含めた、カレントワーキングディレクトリの 絶対パス名の長さが
113 \fBPATH_MAX\fP バイトを超えている場合、 NULL が返され、 \fIerrno\fP に \fBENAMETOOLONG\fP が設定される。
114 (システムによっては、 \fBPATH_MAX\fP は必ずしもコンパイル時に決まる定数ではない点に注意すること。
115 また、ファイルシステムに依存する場合もある。 \fBpathconf\fP(3)  を参照。)  移植性とセキュリティ上の理由から、 \fBgetwd\fP()
116 の利用は推奨されない。
117 .SH 返り値
118 成功すると、これらの関数はカレントワーキングディレクトリの絶対パス名 が入った文字列へのポインタを返す。 \fBgetcwd\fP()  と
119 \fBgetwd\fP()  の場合、返り値は \fIbuf\fP と同じ値になる。
120
121 失敗した場合、これらの関数は NULL を返し、 \fIerrno\fP にエラーを示す値を設定する。 \fIbuf\fP が指す配列の内容は未定義である。
122 .SH エラー
123 .TP 
124 \fBEACCES\fP
125 ファイル名の構成要素に対する読み込みあるいは検索の権限がない。
126 .TP 
127 \fBEFAULT\fP
128 \fIbuf\fP が不正なアドレスを指している。
129 .TP 
130 \fBEINVAL\fP
131 \fIsize\fP 引数が 0 かつ、 \fIbuf\fP 引数が NULL ポインタでない。
132 .TP 
133 \fBEINVAL\fP
134 \fBgetwd\fP(): \fIbuf\fP が NULL である。
135 .TP 
136 \fBENAMETOOLONG\fP
137 \fBgetwd\fP(): 絶対パス名が入った NULL 終端された文字列の長さが \fBPATH_MAX\fP バイトを超えている。
138 .TP 
139 \fBENOENT\fP
140 カレントワーキングディレクトリが削除されている。
141 .TP 
142 \fBERANGE\fP
143 \fIsize\fP 引数の値がワーキングディレクトリの絶対パス名の長さより小さい。 長さには文字列の終端バイトも含まれる。
144 より大きい配列を確保してもう一度実行する必要がある。
145 .SH 準拠
146 \fBgetcwd\fP()  は POSIX.1\-2001 に準拠している。 POSIX.1\-2001 は、 \fIbuf\fP が NULL の場合の
147 \fBgetcwd\fP()  の動作を規定しないままとしている。
148
149 \fBgetwd\fP()  は POSIX.1\-2001 に存在しているが、「過去の名残(LEGACY)」とされている。 POSIX.1\-2008 では、
150 \fBgetwd\fP()  の仕様が削除されている。 代わりに \fBgetcwd\fP()  を使うこと。 POSIX.1\-2001 は \fBgetwd\fP()
151 に関するエラーを定義していない。
152
153 \fBget_current_dir_name\fP()  は GNU 拡張である。
154 .SH 注意
155 Linux では (2.1.92 以降)、 \fBgetcwd\fP()  はシステムコールである。 古いシステムでは \fI/proc/self/cwd\fP
156 を参照する。 システムコールも proc ファイルシステムもない場合、 一般的な実装が呼び出される。 この場合においてのみ、(Linux では)
157 この関数は \fBEACCES\fP で失敗する可能性がある。
158 .LP
159 これらの関数はしばしばカレントワーキングディレクトリの位置を保存し、 後で戻ってくるために利用される。 未使用のファイルディスクリプタが十分ある場合は、
160 現在のディレクトリ (".") を開いて \fBfchdir\fP(2)  を呼び出すほうが普通は高速で信頼性がある。 特に Linux
161 以外のプラットフォームの場合はそうである。
162 .SH 関連項目
163 \fBchdir\fP(2), \fBfchdir\fP(2), \fBopen\fP(2), \fBunlink\fP(2), \fBfree\fP(3),
164 \fBmalloc\fP(3)
165 .SH この文書について
166 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
167 である。プロジェクトの説明とバグ報告に関する情報は
168 http://www.kernel.org/doc/man\-pages/ に書かれている。