basename

Name

basename -- return the last component of a file name

Synopsis

#include <libgen.h>

char * basename(const char * path);

Description

In the source standard, basename() is implemented as a macro causing it to behave as described in POSIX 1003.1-2008 (ISO/IEC 9945-2009), and is equivalent to the function __xpg_basename(). If the macro is undefined, basename() from the binary standard is used, with differences as described here:

The string identified by path shall not be modified.

If path is "/", or ends with a trailing '/' character, the basename() function shall return a pointer to an empty string.

Return Value

On success, the basename() function shall return a pointer to the final component of path. Otherwise, it shall return a null pointer.

See Also

__xpg_basename()