[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, 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"
"/" "/"

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The dirname subroutine.


[ Previous | Next | Contents | Glossary | Home | Search ]