Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getcwd(3) — Ultrix-11 3.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

pwd(1)

malloc(3)

popen(3s)

getcwd(3)

NAME

getcwd − get path-name of current working directory

SYNTAX

char *getcwd(buf, size)
char *buf;
int size;

DESCRIPTION

The getcwd 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, 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);

DIAGNOSTICS

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

[EINVAL]
The size is zero. 

[ENDMEM]
No space is available.

[ERANGE]
The size is not large enough to hold the pathname. 

SEE ALSO

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

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