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 Edition, Standard for Information Technology
92       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
93       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
94       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
95       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
96       event of any discrepancy between this version and the original IEEE and
97       The  Open Group Standard, the original IEEE and The Open Group Standard
98       is the referee document. The original Standard can be  obtained  online
99       at http://www.unix.org/online.html .
100
101       Any  typographical  or  formatting  errors that appear in this page are
102       most likely to have been introduced during the conversion of the source
103       files  to  man page format. To report such errors, see https://www.ker
104       nel.org/doc/man-pages/reporting_bugs.html .
105
106
107
108IEEE/The Open Group                  2013                            CHDIR(3P)
Impressum