.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) .\" .\" 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. .\" Modified Wed Jul 21 22:35:42 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified 18 Mar 1996 by Martin Schulze (joey@infodrom.north.de): .\" Corrected description of getwd(). .\" Modified Sat Aug 21 12:32:12 MET 1999 by aeb - applied fix by aj .\" Modified Mon Dec 11 13:32:51 MET 2000 by aeb .\" Modified Thu Apr 22 03:49:15 CEST 2002 by Roger Luethi .\" .\" Japanese Version Copyright (c) 1997 IMAMURA Nobutaka .\" all rights reserved. .\" Translated Fri Feb 14 12:40:22 JST 1997 .\" by IMAMURA Nobutaka .\" Modified Thu Dec 8 05:08:44 JST 1999 .\" by Kentaro Shirakata .\" Modified Sun Mar 12 21:08:44 JST 2000 .\" by HANATAKA Shinya .\" Updated 2001-01-29 by Kentaro Shirakata .\" Updated 2002-03-23 by Kentaro Shirakata .\" Updated 2002-10-17 by Kentaro Shirakata .\" Updated 2007-01-01 by Kentaro Shirakata .\" Updated 2008-08-21, Akihiro MOTOKI , LDP v3.07 .\" .\" WORD: current working directory カレントワーキングディレクトリ .\" WORD: LEGACY 「過去の名残(LEGACY)」 .\" .TH GETCWD 3 2010-09-20 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O getcwd, getwd, get_current_dir_name \- Get current working directory getcwd, getwd, get_current_dir_name \- カレントワーキングディレクトリ名の取得 .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "char *getcwd(char *" buf ", size_t " size ); .sp .BI "char *getwd(char *" buf ); .sp .B "char *get_current_dir_name(void);" .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .sp .in .BR get_current_dir_name (): .RS _GNU_SOURCE .RE .sp .BR getwd (): .ad l .RS 4 .PD 0 .TP 4 .\"O Since glibc 2.10: glibc 2.10 以降: .nf _BSD_SOURCE || (_XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) && !(_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700) .fi .TP 4 .\"O Before glibc 2.10: glibc 2.10 より前: _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .PD .RE .ad b .\"O .SH DESCRIPTION .SH 説明 .\"O These functions return a null-terminated string containing an .\"O absolute pathname that is the current working directory of .\"O the calling process. .\"O The pathname is returned as the function result and via the argument .\"O .IR buf , .\"O if present. これらの関数は、呼び出したプロセスのカレントワーキングディレクトリの 絶対パス名 (absolute pathname) が入った文字列を返す。 返される文字列は NULL で終端される。 パス名は関数の結果として返され、引数 .I buf がある場合は .I buf 経由でも返される。 .\"O The .\"O .BR getcwd () .\"O function copies an absolute pathname of the current working directory .\"O to the array pointed to by .\"O .IR buf , .\"O which is of length .\"O .IR size . .BR getcwd () 関数はカレントワーキングディレクトリの絶対パス名を .I buf で示された .I size 長の配列にコピーする。 .PP .\"O If the length of the absolute pathname of the current working directory, .\"O including the terminating null byte, exceeds .\"O .I size .\"O bytes, NULL is returned, and .\"O .I errno .\"O is set to .\"O .BR ERANGE ; .\"O an application should check for this error, and allocate a larger .\"O buffer if necessary. 終端の NULL バイトも含めた、カレントワーキングディレクトリの 絶対パス名の長さが .I size バイトを超えている場合は、返り値として NULL が返り .I errno に .B ERANGE がセットされる。 アプリケーションはこのエラーをチェックし、 必要に応じてより長いバッファを用意すべきである。 .PP .\"O As an extension to the POSIX.1-2001 standard, Linux (libc4, libc5, glibc) .\"O .BR getcwd () .\"O allocates the buffer dynamically using .\"O .BR malloc (3) .\"O if .\"O .I buf .\"O is NULL. .\"O In this case, the allocated buffer has the length .\"O .I size .\"O unless .\"O .I size .\"O is zero, when .\"O .I buf .\"O is allocated as big as necessary. .\"O The caller should .\"O .BR free (3) .\"O the returned buffer. POSIX.1-2001 標準の拡張として、 Linux (libc4, libc5, glibc) では .I buf が NULL の場合、 .BR getcwd () は必要なバッファを .BR malloc (3) を用いて動的に割り当てる。 この場合、 .I size が 0 の場合を除き、バッファの長さは .I size となる。 .I size が 0 の場合には必要な大きさが確保される。 呼び出し側で、返されたバッファを .BR free (3) すべきである。 .\"O .BR get_current_dir_name () .\"O will .\"O .BR malloc (3) .\"O an array big enough to hold the absolute pathname of .\"O the current working directory. .\"O If the environment .\"O variable .\"O .B PWD .\"O is set, and its value is correct, then that value will be returned. .BR get_current_dir_name () はカレントワーキングディレクトリの絶対パス名を収めるのに 十分な大きさの配列を .BR malloc (3) で獲得する。環境変数 .B PWD が設定されておりその値が正しければ、その値が返される。 .\"O The caller should .\"O .BR free (3) .\"O the returned buffer. 呼び出し側で、返されたバッファを .BR free (3) すべきである。 .\"O .BR getwd () .\"O does not .\"O .BR malloc (3) .\"O any memory. .\"O The .\"O .I buf .\"O argument should be a pointer to an array at least .\"O .B PATH_MAX .\"O bytes long. .\"O If the length of the absolute pathname of the current working directory, .\"O including the terminating null byte, exceeds .\"O .B PATH_MAX .\"O bytes, NULL is returned, and .\"O .I errno .\"O is set to .\"O .BR ENAMETOOLONG . .BR getwd () は .BR malloc (3) によるメモリ獲得を一切行なわない。 .I buf 引数は少なくとも .B PATH_MAX バイトの長さを持つ配列へのポインタである必要がある。 終端の NULL バイトも含めた、カレントワーキングディレクトリの 絶対パス名の長さが .B PATH_MAX バイトを超えている場合、 NULL が返され、 .I errno に .B ENAMETOOLONG が設定される。 .\"O (Note that on some systems, .\"O .B PATH_MAX .\"O may not be a compile-time constant; .\"O furthermore, its value may depend on the file system, see .\"O .BR pathconf (3).) .\"O For portability and security reasons, use of .\"O .BR getwd () .\"O is deprecated. (システムによっては、 .B PATH_MAX は必ずしもコンパイル時に決まる定数ではない点に注意すること。 また、ファイルシステムに依存する場合もある。 .BR pathconf (3) を参照。) 移植性とセキュリティ上の理由から、 .BR getwd () の利用は推奨されない。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, these functions return a pointer to a string containing .\"O the pathname of the current working directory. .\"O In the case .\"O .BR getcwd () .\"O and .\"O .BR getwd () .\"O this is the same value as .\"O .IR buf. 成功すると、これらの関数はカレントワーキングディレクトリの絶対パス名 が入った文字列へのポインタを返す。 .BR getcwd () と .BR getwd () の場合、返り値は .I buf と同じ値になる。 .\"O On failure, these functions return NULL, and .\"O .I errno .\"O is set to indicate the error. .\"O The contents of the array pointed to by .\"O .I buf .\"O are undefined on error. 失敗した場合、これらの関数は NULL を返し、 .I errno にエラーを示す値を設定する。 .I buf が指す配列の内容は未定義である。 .\"O .SH ERRORS .SH エラー .TP .B EACCES .\"O Permission to read or search a component of the filename was denied. ファイル名の構成要素に対する読み込みあるいは検索の権限がない。 .TP .B EFAULT .\"O .I buf .\"O points to a bad address. .I buf が不正なアドレスを指している。 .TP .B EINVAL .\"O The .\"O .I size .\"O argument is zero and .\"O .I buf .\"O is not a null pointer. .I size 引数が 0 かつ、 .I buf 引数が NULL ポインタでない。 .TP .B EINVAL .\"O .BR getwd (): .\"O .I buf .\"O is NULL. .BR getwd (): .I buf が NULL である。 .TP .B ENAMETOOLONG .\"O .BR getwd (): .\"O The size of the null-terminated absolute pathname string exceeds .\"O .B PATH_MAX .\"O bytes. .BR getwd (): 絶対パス名が入った NULL 終端された文字列の長さが .B PATH_MAX バイトを超えている。 .TP .B ENOENT .\"O The current working directory has been unlinked. カレントワーキングディレクトリが削除されている。 .TP .B ERANGE .\"O The .\"O .I size .\"O argument is less than the length of the absolute pathname of the .\"O working directory, including the terminating null byte. .\"O You need to allocate a bigger array and try again. .I size 引数の値がワーキングディレクトリの絶対パス名の長さより小さい。 長さには文字列の終端バイトも含まれる。 より大きい配列を確保してもう一度実行する必要がある。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O .BR getcwd () .\"O conforms to POSIX.1-2001. .BR getcwd () は POSIX.1-2001 に準拠している。 .\"O Note however that POSIX.1-2001 leaves the behavior of .\"O .BR getcwd () .\"O unspecified if .\"O .I buf .\"O is NULL. POSIX.1-2001 は、 .I buf が NULL の場合の .BR getcwd () の動作を規定しないままとしている。 .\"O .BR getwd () .\"O is present in POSIX.1-2001, but marked LEGACY. .BR getwd () は POSIX.1-2001 に存在しているが、「過去の名残(LEGACY)」とされている。 .\"O POSIX.1-2008 removes the specification of .\"O .BR getwd (). .\"O Use .\"O .BR getcwd () .\"O instead. .\"O POSIX.1-2001 .\"O does not define any errors for .\"O .BR getwd (). POSIX.1-2008 では、 .BR getwd () の仕様が削除されている。 代わりに .BR getcwd () を使うこと。 POSIX.1-2001 は .BR getwd () に関するエラーを定義していない。 .\"O .BR get_current_dir_name () .\"O is a GNU extension. .BR get_current_dir_name () は GNU 拡張である。 .\"O .SH NOTES .SH 注意 .\"O Under Linux, the function .\"O .BR getcwd () .\"O is a system call (since 2.1.92). Linux では (2.1.92 以降)、 .BR getcwd () はシステムコールである。 .\"O On older systems it would query .\"O .IR /proc/self/cwd . 古いシステムでは .I /proc/self/cwd を参照する。 .\"O If both system call and proc file system are missing, a .\"O generic implementation is called. .\"O Only in that case can .\"O these calls fail under Linux with .\"O .BR EACCES . システムコールも proc ファイルシステムもない場合、 一般的な実装が呼び出される。 この場合においてのみ、(Linux では) この関数は .B EACCES で失敗する可能性がある。 .LP .\"O These functions are often used to save the location of the current working .\"O directory for the purpose of returning to it later. .\"O Opening the current .\"O directory (".") and calling .\"O .BR fchdir (2) .\"O to return is usually a faster and more reliable alternative when sufficiently .\"O many file descriptors are available, especially on platforms other than Linux. これらの関数はしばしばカレントワーキングディレクトリの位置を保存し、 後で戻ってくるために利用される。 未使用のファイルディスクリプタが十分ある場合は、 現在のディレクトリ (".") を開いて .BR fchdir (2) を呼び出すほうが普通は高速で信頼性がある。 特に Linux 以外のプラットフォームの場合はそうである。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR chdir (2), .BR fchdir (2), .BR open (2), .BR unlink (2), .BR free (3), .BR malloc (3)