.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992 .\" .\" 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. .\" .\" Modified by Michael Haardt .\" Modified 1993-07-21 by Rik Faith .\" Modified 1995-04-15 by Michael Chastain : .\" Added 'fchdir'. Fixed bugs in error section. .\" Modified 1996-10-21 by Eric S. Raymond .\" Modified 1997-08-21 by Joseph S. Myers .\" Modified 2004-06-23 by Michael Kerrisk .\" .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara .\" all rights reserved. .\" Translated 1996-06-24, Yosiaki Yanagihara .\" Modified 1997-12-13, HANATAKA Shinya .\" Updated & Modified 2005-02-05, Yuichi SATO .\" Updated 2006-08-12, Akihiro MOTOKI , LDP v2.39 .\" Updated 2007-09-04, Akihiro MOTOKI , LDP v2.64 .\" .TH CHDIR 2 2010-09-26 "Linux" "Linux Programmer's Manual" .SH 名前 chdir, fchdir \- 作業ディレクトリの変更 .SH 書式 .B #include .sp .BI "int chdir(const char *" path ); .br .BI "int fchdir(int " fd ); .sp .in -4n glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR fchdir (): .PD 0 .ad l .RS 4 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .br || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L .RE .ad .PD .SH 説明 .BR chdir () は、呼び出し元プロセスの現在の作業ディレクトリ (current working directory) を、 .I path に指定されたディレクトリに変更する。 .PP .BR fchdir () は、ディレクトリがオープンされたファイル・ディスクリプターとして 指定される以外は、 .BR chdir () と同じである。 .SH 返り値 成功すると、0 を返す。失敗すると、\-1 を返し、 .I errno に適切な値をセットする。 .SH エラー ファイルシステムによっては他のエラーが返される事がある。 .BR chdir () で一般的なエラーを以下に挙げる: .TP .B EACCES .I path の構成要素のいずれかに検索許可 (search permission) がない .RB ( path_resolution (7) も参照すること)。 .TP .B EFAULT 割り当てられたアドレス空間外を .I path が指している。 .TP .B EIO I/O エラーが発生した。 .TP .B ELOOP .I path を解決する際に遭遇したシンボリック・リンクが多過ぎる。 .TP .B ENAMETOOLONG .I path が長過ぎる。 .TP .B ENOENT そのディレクトリは存在しない。 .TP .B ENOMEM カーネルに十分なメモリがない。 .TP .B ENOTDIR .I path の構成要素がディレクトリではない。 .PP .BR fchdir () で一般的なエラーを以下に挙げる: .TP .B EACCES .I fd をディレクトリとしてオープンするための検索許可がない。 .TP .B EBADF .I fd が適切なファイル・ディスクリプターでない。 .SH 準拠 SVr4, 4.4BSD, POSIX.1-2001. .SH 注意 現在の作業ディレクトリは、相対パス名 (\(aq/\(aq) で始まっていないパス名) を 解釈する際の開始点である。 .BR fork (2) で作成された子プロセスは、親プロセスの現在の作業ディレクトリを 継承する。 .BR execve (2) の前後で、現在の作業ディレクトリは変更されない。 .BR fchdir () のプロトタイプが有効になるのは、 .B _BSD_SOURCE を定義した場合か、 .B _XOPEN_SOURCE を値 500 で定義した場合のみである。 .SH 関連項目 .BR chroot (2), .BR getcwd (3), .BR path_resolution (7)