[Previous]
[Contents]
[Next]

basename()

find the part of a string after the last "/"

Synopsis:

#include <unistd.h>
char *basename( char *string );

Description:

The basename() function is equivalent to the 1003.2 basename utility. It returns a pointer to the first character following the last slash (/) found in string, or the first character of string if no slashes are found.

Returns:

A pointer to the basename portion of string.

Examples:

#include <unistd.h>
#include  <stdio.h>

int main( void )
  {
    /*
     * basename returns a pointer to "three".
     */
    printf( "%s\n", basename( "one/two/three" ) );

    /*
     * basename returns a pointer to "one".
     */
    printf( "%s\n", basename( "one" ) );

    /*
     * basename returns a pointer to a null character.
     */
    printf( "%s\n", basename( "one/" ) );
    return (EXIT_SUCCESS);
  }

Classification:

QNX

Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

basename


[Previous]
[Contents]
[Next]