Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getcwd(3) — SunOS 3.2/SYS4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

malloc(3)

popen(3S)

pwd(1)

GETCWD(3)  —  C LIBRARY FUNCTIONS

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(3). 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.

EXAMPLE

char ∗cwd, ∗getcwd();
.
.
.
if ((cwd = getcwd((char ∗)NULL, 64)) == NULL) {

perror(“pwd”);
exit(1);

}
printf(“%s\n”, cwd);

SEE ALSO

malloc(3), popen(3S), pwd(1)

DIAGNOSTICS

Returns NULL with errno set if size is not large enough, or if an error ocurrs in a lower-level function. 

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 systems. 

Sun Release 3.2  —  Last change: 15 April 1986

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026