basename(3C)
NAME
basename(), dirname() − extract components of a path name
SYNOPSIS
#include <libgen.h>
char *basename(char *path);
char *dirname(char *path);
DESCRIPTION
basename() takes the path name pointed to by path and returns a pointer to the final component of the path name, deleting any trailing ’/’ characters. If the string consists entirely of ’/’ characters, basename() returns a pointer to the string "/". If path is a null pointer or points to the empty string, basename() returns a pointer to the string ".".
dirname() takes the path name pointed to by path and returns a pointer to a string that is a path name of the parent directory of that file. If path is a null pointer, points to the empty string, or does not contain a ’/’ character, then dirname() returns a pointer to the string ".".
RETURN VALUE
basename() returns a pointer to the final component of path.
dirname() returns a pointer to a string that is the parent directory of path.
EXAMPLES
The following code fragment calls basename() and dirname().
#include <libgen.h>
char *path="/usr/local/bin/foo";
char *base, dir;
base=basename(path);
dir=dirname(path);
WARNINGS
The return value points to static data whose content is overwritten by each call.
AUTHOR
basename() and dirname() were developed by HP.
SEE ALSO
STANDARDS CONFORMANCE
basename(): XPG4.2
dirname(): XPG4.2
Hewlett-Packard Company — HP-UX Release 10.20: July 1996