1GETCWD(2) Linux Programmer's Manual GETCWD(2)
2
3
4
6 getcwd - get current working directory
7
9 /*
10 * This page documents the getcwd(2) system call, which
11 * is not defined in any user-space header files; you should
12 * use getcwd(3) defined in <unistd.h> instead in applications.
13 */
14
15 long getcwd(char *buf, unsigned long size);
16
18 The getcwd() function copies an absolute pathname of the current work‐
19 ing directory to the array pointed to by buf, which is of length size.
20
21 If the current absolute path name would require a buffer longer than
22 size elements, -1 is returned, and errno is set to ERANGE; an applica‐
23 tion should check for this error, and allocate a larger buffer if nec‐
24 essary.
25
26 If buf is NULL, the behaviour of getcwd() is undefined.
27
28
30 -1 on failure (for example, if the current directory is not readable),
31 with errno set accordingly, and the number of characters stored in buf
32 on success. The contents of the array pointed to by buf is undefined on
33 error.
34
35 Note that this return value differs from the getcwd(3) library func‐
36 tion, which returns NULL on failure and the address of buf on success.
37
38
40 ENOMEM if user memory cannot be mapped
41
42 ENOENT if directory does not exist (i.e. it has been deleted)
43
44 ERANGE if not enough space available for storing the path
45
46 EFAULT if memory access violation occurs while copying
47
48
50 The getcwd system call is Linux specific, use the getcwd C library
51 function for portability.
52
53
55 getcwd(3)
56
57
58
59Linux 2.4 2003-03-28 GETCWD(2)