Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _XOPEN_SOURCE_EXTENDED 1
#include <libgen.h>
char *dirname(char *path);
The dirname() function takes a pointer to a character string that contains a path name, and returns a pointer to a string that is a path name of the parent directory of that file. Trailing '/' characters in the path are not counted as part of the path.
If path does not contain a '/' then dirname() returns a pointer to the string ".". If path is a NULL pointer or points to an empty string, dirname() returns a pointer to the string ".".
The dirname() function may modify the string pointed to by path.
Input String Output String
"/usr/lib" "/usr"
"/usr/" "/"
"usr" "."
"/" "/"
"." "."
".." "."
If successful, dirname() returns a pointer to a string that is the parent directory of path.
If path is a NULL pointer or points to an empty string, dirname() returns a pointer to a string ".".
There are no errno values defined.