Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _XOPEN_SOURCE_EXTENDED 1
#include <libgen.h>
char *basename(char *path);
The basename() function takes the pathname pointed to by path and returns a pointer to the final component of the pathname, deleting any trailing '/' characters.
If the string consists entirely of the '/' character, basename() returns a pointer to the string “/”.
If path is a NULL pointer or points to an empty string, basename() returns a pointer to the string “.”. The basename() function may modify the string pointed to by path.
Input String Output String
"/usr/lib" "lib"
"/usr/" "usr"
"/" "/"
If successful, basename() returns a pointer to the final component of path.
There are no errno values defined.