Return the last element of a path name.
char *basename (char *path)
Given a pointer to a character string that contains a path name, the basename subroutine deletes trailing "/" characters from path, and then returns a pointer to the last component of path. The "/" character is defined as trailing if it is not the first character in the string.
If path is a null pointer or points to an empty string, a pointer to a static constant "." is returned.
The basename function returns a pointer to the last component of path.
The basename function returns a pointer to a static constant "." if path is a null pointer or points to an empty string.
The basename function may modify the string pointed to by path and may return a pointer to static storage that may then be overwritten by a subsequent call to the basename subroutine.
Input string | Output string |
---|---|
"/usr/lib" | "lib" |
"/usr/" | "usr" |
"/" | "/" |
This subroutine is part of Base Operating System (BOS) Runtime.
The dirname (dirname Subroutine) subroutine.