161181Sbostic.\" Copyright (c) 1980, 1991, 1993 261181Sbostic.\" The Regents of the University of California. All rights reserved. 320062Smckusick.\" 447208Scael.\" %sccs.include.redist.man% 520062Smckusick.\" 6*65100Smckusick.\" @(#)chdir.2 8.2 (Berkeley) 12/11/93 747208Scael.\" 847208Scael.Dd 947208Scael.Dt CHDIR 2 1047208Scael.Os BSD 4 1147208Scael.Sh NAME 1247208Scael.Nm chdir , 1347208Scael.Nm fchdir 1447208Scael.Nd change current working directory 1547208Scael.Sh SYNOPSIS 1647208Scael.Fd #include <unistd.h> 1747208Scael.Ft int 1847208Scael.Fn chdir "const char *path" 1947208Scael.Ft int 2047208Scael.Fn fchdir "int fd" 2147208Scael.Sh DESCRIPTION 2247208ScaelThe 2347208Scael.Fa path 24*65100Smckusickargument points to the pathname of a directory. 2547208ScaelThe 2647208Scael.Fn chdir 2747208Scaelfunction 2847208Scaelcauses the named directory 2947208Scaelto become the current working directory, that is, 3047208Scaelthe starting point for path searches of pathnames not beginning with 3147208Scaela slash, 3247208Scael.Ql / . 3347208Scael.Pp 3447208ScaelThe 3547208Scael.Fn fchdir 3647208Scaelfunction 3738240Smckusickcauses the directory referenced by 3847208Scael.Fa fd 3938240Smckusickto become the current working directory, 4047208Scaelthe starting point for path searches of pathnames not beginning with 4147208Scaela slash, 4247208Scael.Ql / . 4347208Scael.Pp 4420063SmckusickIn order for a directory to become the current directory, 4520063Smckusicka process must have execute (search) access to the directory. 4647208Scael.Sh RETURN VALUES 4720063SmckusickUpon successful completion, a value of 0 is returned. 4847208ScaelOtherwise, a value of -1 is returned and 4947208Scael.Va errno 5047208Scaelis set to indicate 5120063Smckusickthe error. 5247208Scael.Sh ERRORS 5347208Scael.Fn Chdir 5420063Smckusickwill fail and the current working directory will be unchanged if 5520063Smckusickone or more of the following are true: 5647208Scael.Bl -tag -width Er 5747208Scael.It Bq Er ENOTDIR 5821003SmckusickA component of the path prefix is not a directory. 5947208Scael.It Bq Er EINVAL 6021003SmckusickThe pathname contains a character with the high-order bit set. 6147208Scael.It Bq Er ENAMETOOLONG 6221003SmckusickA component of a pathname exceeded 255 characters, 6321003Smckusickor an entire path name exceeded 1023 characters. 6447208Scael.It Bq Er ENOENT 6520063SmckusickThe named directory does not exist. 6647208Scael.It Bq Er ELOOP 6721003SmckusickToo many symbolic links were encountered in translating the pathname. 6847208Scael.It Bq Er EACCES 6920063SmckusickSearch permission is denied for any component of 7020063Smckusickthe path name. 7147208Scael.It Bq Er EFAULT 7247208Scael.Fa Path 7320063Smckusickpoints outside the process's allocated address space. 7447208Scael.It Bq Er EIO 7524439SmckusickAn I/O error occurred while reading from or writing to the file system. 7647208Scael.El 7747208Scael.Pp 7847208Scael.Fn Fchdir 7938240Smckusickwill fail and the current working directory will be unchanged if 8038240Smckusickone or more of the following are true: 8147208Scael.Bl -tag -width Er 8247208Scael.It Bq Er EACCES 8344943SbosticSearch permission is denied for the directory referenced by the 8444943Sbosticfile descriptor. 8547208Scael.It Bq Er ENOTDIR 8638240SmckusickThe file descriptor does not reference a directory. 8747208Scael.It Bq Er EBADF 8844943SbosticThe argument 8947208Scael.Fa fd 9044943Sbosticis not a valid file descriptor. 9147208Scael.El 9247208Scael.Sh SEE ALSO 9347208Scael.Xr chroot 2 9447208Scael.Sh STANDARDS 9547208Scael.Fn Chdir 9647208Scaelis expected to conform to IEEE Std 1003.1-1988 9747208Scael.Pq Dq Tn POSIX . 9847208Scael.Sh HISTORY 9947208ScaelThe 10047208Scael.Fn fchdir 10147208Scaelfunction call 10247208Scaelappeared in 10347208Scael.Bx 4.2 . 104