GETCWD(S) XENIX System V GETCWD(S)
Name
getcwd - Get the pathname of current working directory.
Syntax
char *getcwd (pnbuf, maxlen)
char *pnbuf;
int maxlen;
Description
getcwd returns a pointer to the current directory pathname.
If pnbuf is a NULL pointer, getcwd will obtain maxlen bytes
of space using malloc(S). In this case, the pointer
returned by getcwd may be used as the argument in a
subsequent call to free(S). If pnbuf is not a NULL pointer,
then the pathname is placed in the space pointed to by pnbuf
and pnbuf is returned.
In all cases, the value of maxlen must be at least two
greater than the length of the pathname to be returned.
getcwd is implemented by using popen(S) to pipe the output
of the pwd(C) command into the specified string space.
Example
char *cwd, *getcwd();
.
.
.
if ((cwd = getcwd((char *)NULL, 64)) == NULL) {
perror(``pwd'');
exit(1);
}
printf(``%s\n'', cwd);
See Also
pwd(C), malloc(S), popen(S)
Page 1 (printed 8/7/87)
GETCWD(S) XENIX System V GETCWD(S)
Errors
[EINVAL] size is zero
[ENOMEM] no space is available
[ERANGE] size not large enough to hold the path name.
Diagnostics
Returns NULL with errno set if maxlen is not large enough.
Notes
maxlen must be 2 more than the true length of the pathname.
Page 2 (printed 8/7/87)