Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

basename - return last element of pathname

&pagelevel(4)&pagelevel

Syntax

#include <libgen.h>

char *basename (char *path);

Description

When basename() is passed a pointer to a null-terminated string which contains a pathname, basename() returns a pointer to the last element of path.
Terminating slash (/) characters are deleted.

If the passed string only consists of the ’/’ character, a pointer to the ’/’ string is returned.

If path or *path is zero, a pointer to the ’.’ string is returned.

basename() is not reentrant.

Return val.

Pointer to the last component of path.

Example

Input string        Output pointer 
/usr/lib            lib
/usr/               usr
/                   /

Notes

basename() works on the passed string. If necessary, the string is modified by overwriting
terminating slashes (’/’) with '\0'.

See also

dirname(), libgen.h.