GETCWD(3C) SysV GETCWD(3C)
NAME
getcwd - get pathname of current working directory
SYNOPSIS
char *getcwd (buf, size)
char *buf;
int size;
DESCRIPTION
getcwd 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, getcwd will obtain size bytes of space using
malloc(3C). In this case, the pointer returned by getcwd may be used as
the argument in a subsequent call to free.
EXAMPLE
void exit(), perror();
.
.
.
if ((cwd = getcwd((char *)NULL, 64)) == NULL) {
perror("pwd");
exit(2);
}
printf("%s\n", cwd);
SEE ALSO
malloc(3C), popen(3S).
pwd(1) in the SysV Command Reference.
DIAGNOSTICS
getcwd returns NULL with errno set if size is not large enough, or if an
error occurs in a lower-level function.