Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getcwd(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

malloc(S)

popen(S)

pwd(C)


 getcwd(S)                      6 January 1993                      getcwd(S)


 Name

    getcwd - get pathname of current working directory

 Syntax


    cc  . . .  -lc


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


 Description

    The getcwd function 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 obtains size bytes of space using
    malloc(S).  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(S) to pipe the output of the
    pwd(C) command into the specified string space.

 Example

    The following is an example of the getcwd function:

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


 Diagnostics

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

    [EINVAL]  If size is zero or not large enough to hold the pathname.


 See also

    malloc(S), popen(S), pwd(C)

 Standards conformance

    getcwd is conformant with:
    AT&T SVID Issue 2;
    X/Open Portability Guide, Issue 3, 1989;
    IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C
    Language] (ISO/IEC 9945-1);
    and NIST FIPS 151-1.


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