Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getcwd(3C) — DG/UX R4.11

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

reentrant(3)

getwd(3C)

malloc(3C)



getcwd(3C)                        SDK R4.11                       getcwd(3C)


NAME
       getcwd - get pathname of current working directory

SYNOPSIS
       #include <unistd.h>

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

DESCRIPTION
       getcwd returns a pointer to the current directory pathname.  The
       value of size must be at least one greater than the length of the
       pathname to be returned.

       If buf is not NULL, the pathname will be stored in the space pointed
       to by buf.

       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.

       getcwd will fail if one or more of the following are true:

       EACCES      A parent directory cannot be read to get its name.

       EINVAL      size is less than or equal to 0.

       ERANGE      size is greater than 0 and less than the length of the
                   pathname plus 1.



          Considerations for Threads Programming
                         +---------+-----------------------------+
                         |         |                      async- |
                         |function | reentrant   cancel   cancel |
                         |         |             point     safe  |
                         +---------+-----------------------------+
                         |getcwd   |     Y         Y        N    |
                         +---------+-----------------------------+

EXAMPLE
       Here is a program that prints the current working directory.

              #include <unistd.h>
              #include <stdio.h>

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

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

SEE ALSO
       reentrant(3), getwd(3C), malloc(3C).


Licensed material--property of copyright holder(s)

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