Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ dirname(3G) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

basename(1)

chdir(2)

basename(3G)

dirname(3G)                                                     dirname(3G)

NAME
     dirname - output parent directory name

SYNOPSIS
     cc [flag ...] file ... -lgen [library ...]

     #include <libgen.h>

     char *dirname(char *path);

DESCRIPTION
     If dirname() is given a pointer to a null-terminated character string
     that contains a file system path name, it returns a pointer to a
     static constant string that is the parent directory of that file. In
     doing this, dirname() sometimes places a null byte in the path name
     before the last element, so the content of path must be disposable.
     Trailing / characters in the path are not counted as part of the path.

     If path or *path is zero, a pointer to a static constant "." is
     returned.

     dirname() and basename() together yield a complete path name.
     dirname(path) is the directory where basename() (path) is found.

EXAMPLES
     A simple filename and the strings "." and ".." all have "." as their
     return value.

     Input string   Output pointer
     _____________________________
     "/usr/lib"     "/usr"
     "/usr/"        "/"
     "usr/"         "."
     "/"            "/"
     "."            "."
     ".."           "."

     The following code reads a path name, changes directory to the
     appropriate directory [see chdir(2)], and opens the file.

     char path[MAXPATHLEN], *pathcopy;
     int fd;
     fgets(path, MAXPATHLEN, stdin);
     pathcopy = strdup(path);
     chdir(dirname(pathcopy));
     fd = open(basename(path), ORDONLY);

SEE ALSO
     basename(1), chdir(2), basename(3G).






Page 1                       Reliant UNIX 5.44                Printed 11/98

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