Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getcwd(3C) — HP-UX 7.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

pwd(1)

malloc(3C)

cdf(4)

GETCWD(3C)

NAME

getcwd, gethcwd − get pathname of current working directory

SYNOPSIS

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

DESCRIPTION

Getcwd places the absolute pathname of the current working directory in the array pointed to by buf, and returns buf.  The value of size must be at least one 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 (see malloc(3C)). Invoking getcwd with buf as a null pointer is not recommended as this functionality may be subject to later withdrawal. 

Gethcwd works the same as getcwd except the returned directory pathname will list all hidden directories (context dependent files, see cdf(4)). 

RETURN VALUE

Upon successful completion, getcwd returns a pointer to the current directory pathname.  Otherwise, it returns NULL with errno set if size is not large enough, or if an error occurs in a lower-level function. 

ERRORS

Getcwd will fail if any of the following is true:

[EINVAL] The size argument is zero or negative. 

[ERANGE] The size argument is greater than zero, but is smaller than the length of the pathname. 

[ENAMETOOLONG] The length of the specified path name exceeds PATH_MAX bytes, or the length of a component of the path name exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect. 

Getcwd may fail if any of the following is true:

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

[EFAULT] Buf points outside the allocated address space of the process.  Getcwd may not always detect this error. 

[ENOMEM] The malloc routine failed to provide size bytes of memory. 

EXAMPLES

char ∗cwd, ∗getcwd();
char buf[PATH_MAX+1];
  .
  .
  .
if ((cwd = getcwd((buf ∗)NULL, PATH_MAX+1)) == NULL) {

perror("pwd");
exit(1);

}
puts(cwd);

AUTHOR

Getcwd was developed by AT&T.  Gethcwd was developed by HP. 

SEE ALSO

pwd(1), malloc(3C), cdf(4). 

STANDARDS CONFORMANCE

getcwd: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

Hewlett-Packard Company  —  HP-UX Release 7.0: Sept 1989

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