[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

basename Subroutine

Purpose

Return the last element of a path name.

Library

Standard C Library (libc.a)

Syntax

#include <libgen.h>

char *basename (char *path)

Description

Given a pointer to a character string that contains a path name, the basename subroutine deletes trailing "/" characters from path, and then returns a pointer to the last component of path. The "/" character is defined as trailing if it is not the first character in the string.

If path is a null pointer or points to an empty string, a pointer to a static constant "." is returned.

Return Values

The basename function returns a pointer to the last component of path.

The basename function returns a pointer to a static constant "." if path is a null pointer or points to an empty string.

The basename function may modify the string pointed to by path and may return a pointer to static storage that may then be overwritten by a subsequent call to the basename subroutine.

Examples

Input string Output string
"/usr/lib" "lib"
"/usr/" "usr"
"/" "/"

Related Information

The dirname (dirname Subroutine) subroutine.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]