1CHDIR(3P) POSIX Programmer's Manual CHDIR(3P)
2
3
4
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
12 chdir — change working directory
13
15 #include <unistd.h>
16
17 int chdir(const char *path);
18
20 The chdir() function shall cause the directory named by the pathname
21 pointed to by the path argument to become the current working direc‐
22 tory; that is, the starting point for path searches for pathnames not
23 beginning with '/'.
24
26 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
27 returned, the current working directory shall remain unchanged, and
28 errno shall be set to indicate the error.
29
31 The chdir() function shall fail if:
32
33 EACCES Search permission is denied for any component of the pathname.
34
35 ELOOP A loop exists in symbolic links encountered during resolution of
36 the path argument.
37
38 ENAMETOOLONG
39 The length of a component of a pathname is longer than
40 {NAME_MAX}.
41
42 ENOENT A component of path does not name an existing directory or path
43 is an empty string.
44
45 ENOTDIR
46 A component of the pathname names an existing file that is nei‐
47 ther a directory nor a symbolic link to a directory.
48
49 The chdir() function may fail if:
50
51 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
52 resolution of the path argument.
53
54 ENAMETOOLONG
55 The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
56 tion of a symbolic link produced an intermediate result with a
57 length that exceeds {PATH_MAX}.
58
59 The following sections are informative.
60
62 Changing the Current Working Directory
63 The following example makes the value pointed to by directory, /tmp,
64 the current working directory.
65
66
67 #include <unistd.h>
68 ...
69 char *directory = "/tmp";
70 int ret;
71
72 ret = chdir (directory);
73
75 None.
76
78 The chdir() function only affects the working directory of the current
79 process.
80
82 None.
83
85 getcwd()
86
87 The Base Definitions volume of POSIX.1‐2017, <unistd.h>
88
90 Portions of this text are reprinted and reproduced in electronic form
91 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
92 table Operating System Interface (POSIX), The Open Group Base Specifi‐
93 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
94 Electrical and Electronics Engineers, Inc and The Open Group. In the
95 event of any discrepancy between this version and the original IEEE and
96 The Open Group Standard, the original IEEE and The Open Group Standard
97 is the referee document. The original Standard can be obtained online
98 at http://www.opengroup.org/unix/online.html .
99
100 Any typographical or formatting errors that appear in this page are
101 most likely to have been introduced during the conversion of the source
102 files to man page format. To report such errors, see https://www.ker‐
103 nel.org/doc/man-pages/reporting_bugs.html .
104
105
106
107IEEE/The Open Group 2017 CHDIR(3P)