getcwd(3)getcwd(3)Namegetcwd - get pathname of working directory
Syntax
char I**getcwd (buf, size)
char I**buf;
int size;
Description
The subroutine returns a pointer to the current directory pathname.
The value of size must be at least two greater than the length of the
pathname to be returned.
If buf is a NULL pointer, will obtain size bytes of space using In this
case, the pointer returned by may be used as the argument in a subse‐
quent call to free.
The function is implemented by using to pipe the output of the command
into the specified string space.
Examples
char ∗cwd, ∗getcwd();
.
.
.
if ((cwd = getcwd((char ∗)NULL, 64)) == NULL) {
perror("pwd");
exit(1);
}
printf("%s\n", cwd);
Return Values
Returns NULL with errno set if size is not large enough, or if an error
occurs in a lower-level function.
Diagnostics
[EINVAL] The size argument is zero or negative.
[ERANGE] The size argument is greater than zero, but is smaller
than the length of the pathname+1;
[EACCES] Read or search permission is denied for a component of
the pathname.
[ENOMEM] Insufficient storage space is available.
See Alsopwd(1), malloc(3), popen(3)getcwd(3)