1CHDIR(3P)                  POSIX Programmer's Manual                 CHDIR(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       chdir — change working directory
14

SYNOPSIS

16       #include <unistd.h>
17
18       int chdir(const char *path);
19

DESCRIPTION

21       The chdir() function shall cause the directory named  by  the  pathname
22       pointed  to  by  the path argument to become the current working direc‐
23       tory; that is, the starting point for path searches for  pathnames  not
24       beginning with '/'.
25

RETURN VALUE

27       Upon successful completion, 0 shall be returned. Otherwise, −1 shall be
28       returned, the current working directory  shall  remain  unchanged,  and
29       errno shall be set to indicate the error.
30

ERRORS

32       The chdir() function shall fail if:
33
34       EACCES Search permission is denied for any component of the pathname.
35
36       ELOOP  A loop exists in symbolic links encountered during resolution of
37              the path argument.
38
39       ENAMETOOLONG
40              The  length  of  a  component  of  a  pathname  is  longer  than
41              {NAME_MAX}.
42
43       ENOENT A  component of path does not name an existing directory or path
44              is an empty string.
45
46       ENOTDIR
47              A component of the pathname names an existing file that is  nei‐
48              ther a directory nor a symbolic link to a directory.
49
50       The chdir() function may fail if:
51
52       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
53              resolution of the path argument.
54
55       ENAMETOOLONG
56              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
57              tion  of  a symbolic link produced an intermediate result with a
58              length that exceeds {PATH_MAX}.
59
60       The following sections are informative.
61

EXAMPLES

63   Changing the Current Working Directory
64       The following example makes the value pointed to  by  directory,  /tmp,
65       the current working directory.
66
67           #include <unistd.h>
68           ...
69           char *directory = "/tmp";
70           int ret;
71
72           ret = chdir (directory);
73

APPLICATION USAGE

75       None.
76

RATIONALE

78       The  chdir() function only affects the working directory of the current
79       process.
80

FUTURE DIRECTIONS

82       None.
83

SEE ALSO

85       getcwd()
86
87       The Base Definitions volume of POSIX.1‐2008, <unistd.h>
88
90       Portions of this text are reprinted and reproduced in  electronic  form
91       from IEEE Std 1003.1, 2013