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