OSDN Git Service

fed0787f123cbcee48a562a784c22c3819a1951c
[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()  does not \fBmalloc\fP(3)  any memory.  The \fIbuf\fP argument should
112 be a pointer to an array at least \fBPATH_MAX\fP bytes long.  If the length of
113 the absolute pathname of the current working directory, including the
114 terminating null byte, exceeds \fBPATH_MAX\fP bytes, NULL is returned, and
115 \fIerrno\fP is set to \fBENAMETOOLONG\fP.  (Note that on some systems, \fBPATH_MAX\fP
116 may not be a compile\-time constant; furthermore, its value may depend on the
117 filesystem, see \fBpathconf\fP(3).)  For portability and security reasons, use
118 of \fBgetwd\fP()  is deprecated.
119 .SH 返り値
120 成功すると、これらの関数はカレントワーキングディレクトリの絶対パス名 が入った文字列へのポインタを返す。 \fBgetcwd\fP()  と
121 \fBgetwd\fP()  の場合、返り値は \fIbuf\fP と同じ値になる。
122
123 失敗した場合、これらの関数は NULL を返し、 \fIerrno\fP にエラーを示す値を設定する。 \fIbuf\fP が指す配列の内容は未定義である。
124 .SH エラー
125 .TP 
126 \fBEACCES\fP
127 ファイル名の構成要素に対する読み込みあるいは検索の権限がない。
128 .TP 
129 \fBEFAULT\fP
130 \fIbuf\fP が不正なアドレスを指している。
131 .TP 
132 \fBEINVAL\fP
133 \fIsize\fP 引数が 0 かつ、 \fIbuf\fP 引数が NULL ポインタでない。
134 .TP 
135 \fBEINVAL\fP
136 \fBgetwd\fP(): \fIbuf\fP が NULL である。
137 .TP 
138 \fBENAMETOOLONG\fP
139 \fBgetwd\fP(): 絶対パス名が入った NULL 終端された文字列の長さが \fBPATH_MAX\fP バイトを超えている。
140 .TP 
141 \fBENOENT\fP
142 カレントワーキングディレクトリが削除されている。
143 .TP 
144 \fBERANGE\fP
145 \fIsize\fP 引数の値がワーキングディレクトリの絶対パス名の長さより小さい。 長さには文字列の終端バイトも含まれる。
146 より大きい配列を確保してもう一度実行する必要がある。
147 .SH 準拠
148 \fBgetcwd\fP()  は POSIX.1\-2001 に準拠している。 POSIX.1\-2001 は、 \fIbuf\fP が NULL の場合の
149 \fBgetcwd\fP()  の動作を規定しないままとしている。
150
151 \fBgetwd\fP()  は POSIX.1\-2001 に存在しているが、「過去の名残(LEGACY)」とされている。 POSIX.1\-2008 では、
152 \fBgetwd\fP()  の仕様が削除されている。 代わりに \fBgetcwd\fP()  を使うこと。 POSIX.1\-2001 は \fBgetwd\fP()
153 に関するエラーを定義していない。
154
155 \fBget_current_dir_name\fP()  は GNU 拡張である。
156 .SH 注意
157 Under Linux, the function \fBgetcwd\fP()  is a system call (since 2.1.92).  On
158 older systems it would query \fI/proc/self/cwd\fP.  If both system call and
159 proc filesystem are missing, a generic implementation is called.  Only in
160 that case can these calls fail under Linux with \fBEACCES\fP.
161 .LP
162 これらの関数はしばしばカレントワーキングディレクトリの位置を保存し、 後で戻ってくるために利用される。 未使用のファイルディスクリプタが十分ある場合は、
163 現在のディレクトリ (".") を開いて \fBfchdir\fP(2)  を呼び出すほうが普通は高速で信頼性がある。 特に Linux
164 以外のプラットフォームの場合はそうである。
165 .SH 関連項目
166 \fBchdir\fP(2), \fBfchdir\fP(2), \fBopen\fP(2), \fBunlink\fP(2), \fBfree\fP(3),
167 \fBmalloc\fP(3)
168 .SH この文書について
169 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
170 である。プロジェクトの説明とバグ報告に関する情報は
171 http://www.kernel.org/doc/man\-pages/ に書かれている。