up | Inhaltsverzeichniss | Kommentar

Manual page for GETCWD(3V)

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.3v In this case, the pointer returned by getcwd() may be used as the argument in a subsequent call to free().

The function is implemented by using popen.3s to pipe the output of the pwd.1 command into the specified string space.

RETURN VALUES

getcwd() returns a pointer to the current directory pathname on success. If size is not large enough, or if an error occurs in a lower-level function, getcwd() returns NULL and sets errno to indicate the error.

ERRORS

EINVAL
size is less than or equal to zero.
ERANGE
size is greater than zero, but is smaller than the length of the pathname plus 1.

If the following condition is detected, getcwd() sets errno to:

EACCES
Read or search permission is denied for a component of the pathname.

EXAMPLES

char *cwd, *getcwd();
.
.
.
if ((cwd = getcwd((char *)NULL, 64)) == NULL) {
perror ("pwd");
exit (1);
}
printf("%s\n", cwd);

SEE ALSO

pwd.1 getwd.3 malloc.3v popen.3s

BUGS

Since this function uses popen() to create a pipe to the pwd command, it is slower than getwd() and gives poorer error diagnostics. getcwd() is provided only for compatibility with other UNIX operating systems.


index | Inhaltsverzeichniss | Kommentar

Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97