flag fields are u_int's
[unix-history] / usr / src / lib / libc / sys / chdir.2
.\" Copyright (c) 1980, 1991 Regents of the University of California.
.\" All rights reserved.
.\"
.\" %sccs.include.redist.man%
.\"
.\" @(#)chdir.2 6.7 (Berkeley) %G%
.\"
.Dd
.Dt CHDIR 2
.Os BSD 4
.Sh NAME
.Nm chdir ,
.Nm fchdir
.Nd change current working directory
.Sh SYNOPSIS
.Fd #include <unistd.h>
.Ft int
.Fn chdir "const char *path"
.Ft int
.Fn fchdir "int fd"
.Sh DESCRIPTION
The
.Fa path
arument points to the pathname of a directory.
The
.Fn chdir
function
causes the named directory
to become the current working directory, that is,
the starting point for path searches of pathnames not beginning with
a slash,
.Ql / .
.Pp
The
.Fn fchdir
function
causes the directory referenced by
.Fa fd
to become the current working directory,
the starting point for path searches of pathnames not beginning with
a slash,
.Ql / .
.Pp
In order for a directory to become the current directory,
a process must have execute (search) access to the directory.
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of -1 is returned and
.Va errno
is set to indicate
the error.
.Sh ERRORS
.Fn Chdir
will fail and the current working directory will be unchanged if
one or more of the following are true:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
.It Bq Er EINVAL
The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
.It Bq Er ENOENT
The named directory does not exist.
.It Bq Er ELOOP
Too many symbolic links were encountered in translating the pathname.
.It Bq Er EACCES
Search permission is denied for any component of
the path name.
.It Bq Er EFAULT
.Fa Path
points outside the process's allocated address space.
.It Bq Er EIO
An I/O error occurred while reading from or writing to the file system.
.El
.Pp
.Fn Fchdir
will fail and the current working directory will be unchanged if
one or more of the following are true:
.Bl -tag -width Er
.It Bq Er EACCES
Search permission is denied for the directory referenced by the
file descriptor.
.It Bq Er ENOTDIR
The file descriptor does not reference a directory.
.It Bq Er EBADF
The argument
.Fa fd
is not a valid file descriptor.
.El
.Sh SEE ALSO
.Xr chroot 2
.Sh STANDARDS
.Fn Chdir
is expected to conform to IEEE Std 1003.1-1988
.Pq Dq Tn POSIX .
.Sh HISTORY
The
.Fn fchdir
function call
appeared in
.Bx 4.2 .