basename

Returns the last component of a path name.

Library:LibC
Classification:Single UNIX
Service:File and Directory I/O

Syntax

  #include <libgen.h> 
   
  char *basename (
     char   *path);
  

Parameters

path

(IN) Points to the buffer containing the directory path.

Return Values

Returns a pointer to the last component in the path:

  • If the path consists of "/" or "\" characters, returns a pointer to the string: "/"

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

No errors have been defined for this function.

Remarks

The basename function takes the path name pointed to by path and returns a pointer to the final component of the pathname, deleting any trailing "/" characters.

IMPORTANT:The basename function is not thread-safe.

See Also