1.\" Copyright (c) 1980, 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)chdir.2 6.7 (Berkeley) 3/10/91 33.\" $Id: chdir.2,v 1.6 1994/04/22 00:13:26 jtc Exp $ 34.\" 35.Dd March 10, 1991 36.Dt CHDIR 2 37.Os BSD 4 38.Sh NAME 39.Nm chdir , 40.Nm fchdir 41.Nd change current working directory 42.Sh SYNOPSIS 43.Fd #include <unistd.h> 44.Ft int 45.Fn chdir "const char *path" 46.Ft int 47.Fn fchdir "int fd" 48.Sh DESCRIPTION 49The 50.Fa path 51argument points to the pathname of a directory. 52The 53.Fn chdir 54function 55causes the named directory 56to become the current working directory, that is, 57the starting point for path searches of pathnames not beginning with 58a slash, 59.Ql / . 60.Pp 61The 62.Fn fchdir 63function 64causes the directory referenced by 65.Fa fd 66to become the current working directory, 67the starting point for path searches of pathnames not beginning with 68a slash, 69.Ql / . 70.Pp 71In order for a directory to become the current directory, 72a process must have execute (search) access to the directory. 73.Sh RETURN VALUES 74Upon successful completion, a value of 0 is returned. 75Otherwise, a value of -1 is returned and 76.Va errno 77is set to indicate 78the error. 79.Sh ERRORS 80.Fn Chdir 81will fail and the current working directory will be unchanged if 82one or more of the following are true: 83.Bl -tag -width Er 84.It Bq Er ENOTDIR 85A component of the path prefix is not a directory. 86.It Bq Er ENAMETOOLONG 87A component of a pathname exceeded 88.Dv {NAME_MAX} 89characters, or an entire path name exceeded 90.Dv {PATH_MAX} 91characters. 92.It Bq Er ENOENT 93The named directory does not exist. 94.It Bq Er ELOOP 95Too many symbolic links were encountered in translating the pathname. 96.It Bq Er EACCES 97Search permission is denied for any component of 98the path name. 99.It Bq Er EFAULT 100.Fa Path 101points outside the process's allocated address space. 102.It Bq Er EIO 103An I/O error occurred while reading from or writing to the file system. 104.El 105.Pp 106.Fn Fchdir 107will fail and the current working directory will be unchanged if 108one or more of the following are true: 109.Bl -tag -width Er 110.It Bq Er EACCES 111Search permission is denied for the directory referenced by the 112file descriptor. 113.It Bq Er ENOTDIR 114The file descriptor does not reference a directory. 115.It Bq Er EBADF 116The argument 117.Fa fd 118is not a valid file descriptor. 119.El 120.Sh SEE ALSO 121.Xr chroot 2 122.Sh STANDARDS 123The 124.Fn chdir 125is expected to conform to 126.St -p1003.1-88 . 127.Sh HISTORY 128The 129.Fn fchdir 130function call 131appeared in 132.Bx 4.2 . 133