Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getcwd(3C) — Interactive 2.2

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

malloc(3C)

popen(3S)

pwd(1)



          getcwd(3C)       INTERACTIVE UNIX System (POSIX)       getcwd(3C)



          NAME
               getcwd - get path name of current working directory

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

          DESCRIPTION
               The getcwd function returns a pointer to the current direc-
               tory path name.  The value of size must be at least two
               greater than the length of the path name 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.

               The function is implemented by using popen(3S) to pipe the
               output of the pwd(1) command into the specified string
               space.

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

          SEE ALSO
               malloc(3C), popen(3S).
               pwd(1) in the INTERACTIVE UNIX System User's/System
               Administrator's Reference Manual.

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

               [EINVAL]       The size argument is less than or equal to
                              zero.

               [ERANGE]       The size argument is greater than zero, but
                              is smaller than the length of the path name
                              plus 1.







          Rev. 1.2                                                   Page 1



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