basename(3G)


basename -- return the last element of a path name

Synopsis

   cc [flag . . . ] file . . . -lgen [library] . . . 
   

#include <libgen.h>

char *basename(const char *path);

Description

Given a pointer to a null-terminated character string that contains a path name, basename returns a pointer to the last element of path. Trailing ``/'' characters are deleted. If the string pointed to by path contains / only, basename returns a pointer to /.

If path or *path is zero, pointer to a static constant ``.'' is returned.

References

basename(1), dirname(3G)

Examples

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

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

30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.