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