1CHDIR(P) POSIX Programmer's Manual CHDIR(P)
2
3
4
6 chdir - change working directory
7
9 #include <unistd.h>
10
11 int chdir(const char *path);
12
13
15 The chdir() function shall cause the directory named by the pathname
16 pointed to by the path argument to become the current working direcā
17 tory; that is, the starting point for path searches for pathnames not
18 beginning with '/' .
19
21 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
22 returned, the current working directory shall remain unchanged, and
23 errno shall be set to indicate the error.
24
26 The chdir() function shall fail if:
27
28 EACCES Search permission is denied for any component of the pathname.
29
30 ELOOP A loop exists in symbolic links encountered during resolution of
31 the path argument.
32
33 ENAMETOOLONG
34 The length of the path argument exceeds {PATH_MAX} or a pathname
35 component is longer than {NAME_MAX}.
36
37 ENOENT A component of path does not name an existing directory or path
38 is an empty string.
39
40 ENOTDIR
41 A component of the pathname is not a directory.
42
43
44 The chdir() function may fail if:
45
46 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
47 resolution of the path argument.
48
49 ENAMETOOLONG
50 As a result of encountering a symbolic link in resolution of the
51 path argument, the length of the substituted pathname string
52 exceeded {PATH_MAX}.
53
54
55 The following sections are informative.
56
58 Changing the Current Working Directory
59 The following example makes the value pointed to by directory, /tmp,
60 the current working directory.
61
62
63 #include <unistd.h>
64 ...
65 char *directory = "/tmp";
66 int ret;
67
68
69 ret = chdir (directory);
70
72 None.
73
75 The chdir() function only affects the working directory of the current
76 process.
77
79 None.
80
82 getcwd() , the Base Definitions volume of IEEE Std 1003.1-2001,
83 <unistd.h>
84
86 Portions of this text are reprinted and reproduced in electronic form
87 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
88 -- Portable Operating System Interface (POSIX), The Open Group Base
89 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
90 Electrical and Electronics Engineers, Inc and The Open Group. In the
91 event of any discrepancy between this version and the original IEEE and
92 The Open Group Standard, the original IEEE and The Open Group Standard
93 is the referee document. The original Standard can be obtained online
94 at http://www.opengroup.org/unix/online.html .
95
96
97
98IEEE/The Open Group 2003 CHDIR(P)