version 1, including all changes.
.
Rev |
Author |
# |
Line |
1 |
perry |
1 |
GETCWD |
|
|
2 |
!!!GETCWD |
|
|
3 |
NAME |
|
|
4 |
SYNOPSIS |
|
|
5 |
DESCRIPTION |
|
|
6 |
RETURN VALUE |
|
|
7 |
CONFORMING TO |
|
|
8 |
SEE ALSO |
|
|
9 |
---- |
|
|
10 |
!!NAME |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
getcwd, get_current_dir_name, getwd - Get current working directory |
|
|
14 |
!!SYNOPSIS |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
__#include |
|
|
18 |
__''buf''__, size_t__ ''size''__); |
|
|
19 |
char *get_current_dir_name(void); |
|
|
20 |
char *getwd(char *__''buf''__); |
|
|
21 |
__ |
|
|
22 |
!!DESCRIPTION |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
The __getcwd__() function copies an absolute pathname of |
|
|
26 |
the current working directory to the array pointed to by |
|
|
27 |
''buf'', which is of length ''size''. |
|
|
28 |
|
|
|
29 |
|
|
|
30 |
If the current absolute path name would require a buffer |
|
|
31 |
longer than ''size'' elements, __NULL__ is returned, |
|
|
32 |
and ''errno'' is set to __ERANGE__; an application |
|
|
33 |
should check for this error, and allocate a larger buffer if |
|
|
34 |
necessary. |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
If ''buf'' is NULL, the behaviour of __getcwd__() is |
|
|
38 |
undefined. |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
As an extension to the POSIX.1 standard, Linux (libc4, |
|
|
42 |
libc5, glibc) __getcwd()__ allocates the buffer |
|
|
43 |
dynamically using __malloc()__ if ''buf'' is |
|
|
44 |
__NULL__ on call. In this case, the allocated buffer has |
|
|
45 |
the length ''size'' unless ''size'' is zero, when |
|
|
46 |
''buf'' is allocated as big as necessary. It is possible |
|
|
47 |
(and, indeed, advisable) to __free()__ the buffers if |
|
|
48 |
they have been obtained this way. |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
__get_current_dir_name__, which is only prototyped if |
|
|
52 |
___GNU_SOURCE__ is defined, will malloc(3) an |
|
|
53 |
array big enough to hold the current directory name. If the |
|
|
54 |
environment variable __PWD__ is set, and its value is |
|
|
55 |
correct, then that value will be returned. |
|
|
56 |
|
|
|
57 |
|
|
|
58 |
__getwd__, which is only prototyped if ___BSD_SOURCE__ |
|
|
59 |
or ___XOPEN_SOURCE_EXTENDED__ is defined, will not |
|
|
60 |
malloc(3) any memory. The ''buf'' argument should |
|
|
61 |
be a pointer to an array at least __PATH_MAX__ bytes |
|
|
62 |
long. __getwd__ does only return the first |
|
|
63 |
__PATH_MAX__ bytes of the actual pathname. |
|
|
64 |
!!RETURN VALUE |
|
|
65 |
|
|
|
66 |
|
|
|
67 |
__NULL__ on failure (for example, if the current |
|
|
68 |
directory is not readable), with ''errno'' set |
|
|
69 |
accordingly, and ''buf'' on success. The contents of the |
|
|
70 |
array pointed to by ''buf'' is undefined on |
|
|
71 |
error. |
|
|
72 |
!!CONFORMING TO |
|
|
73 |
|
|
|
74 |
|
|
|
75 |
POSIX.1 |
|
|
76 |
!!SEE ALSO |
|
|
77 |
|
|
|
78 |
|
|
|
79 |
chdir(2), free(3), |
|
|
80 |
malloc(3) |
|
|
81 |
---- |