basename

Returns the last component of a path name.

Format

#include  <libgen.h>

char *basename  (char *path);
Function Variants This function also has variants named _basename32 and _basename64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Argument

path
A UNIX style pathname from which the base path name is extracted.

Description

This function takes the UNIX style pathname pointed to by path and returns a pointer to the pathname's final component, deleting any trailing slash (/) characters.

If path consists entirely of the slash (/) character, the function returns a pointer to the string "/".

If path is a NULL pointer or points to an empty string, the function returns a pointer to the string ".".

The basename function can modify the string pointed to by path.

Return Values
A pointer to the final component of path
"/"  If path consists entirely of the '/' character. 
"."  If path is a NULL pointer or points to an empty string. 


Previous Page | Next Page | Table of Contents | Index