dirname3
Extract the directory part of a pathname
Usage
#include <libgen.h>
char *
dirname(char *path);
Overview
The dirname() function is the converse of basename(3); it returns a pointer to the parent directory of the pathname pointed to by path. Any trailing ‘/’ characters are not counted as part of the directory name.
Implementation notes
This implementation of dirname() uses the buffer provided by the caller to store the resulting parent directory. Other vendor implementations may return a pointer to internal storage space instead. The advantage of the former approach is that it ensures thread-safety, while also placing no upper limit on the supported length of the pathname.
Return values
If path is a null pointer, the empty string, or contains no ‘/’ characters, dirname() returns a pointer to the string ".", signifying the current directory. Otherwise, it returns a pointer to the parent directory of path.
Releases
67 releases since FreeBSD 4.2-RELEASE; the text changed 40 times.