basename3
Extract the base portion of a pathname
Usage
#include <libgen.h>
char *
basename(char *path);
Overview
The basename() function returns the last component from the pathname pointed to by path, deleting any trailing ‘/’ characters.
Implementation notes
This implementation of basename() uses the buffer provided by the caller to store the resulting pathname component. 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 consists entirely of ‘/’ characters, a pointer to the string "/" is returned. If path is a null pointer or the empty string, a pointer to the string "." is returned. Otherwise, it returns a pointer to the last component of path.
Releases
67 releases since FreeBSD 4.2-RELEASE; the text changed 40 times.