Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ gethcwd(3C) — HP-UX ANSI C A.09.00

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

#include <unistd.h>

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

char *gethcwd(char *buf, size_t 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() obtains size bytes of space using malloc() (see malloc(3C)). In this case, the pointer returned by getcwd() can 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 because this functionality may be removed from the HP-UX operating system in a future release. 

gethcwd() works the same as getcwd() except the returned directory pathname lists 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() fails if any of the following conditions are encountered:

[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 conditions are encountered:

[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] malloc() 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(): AES, SVID2, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

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