Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/b/basename.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/b/basename.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/b/basename.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/b/basename.html on line 8
Find the part of a string after the last slash (/)
#include <libgen.h>
char* basename( char* path );
- path
- The string to parse.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The basename() function takes the pathname pointed to by
path and returns a pointer to the final component of
the pathname, deleting any trailing “/” characters.
The basename() function returns:
- A pointer to the string “/”
- If the string consists entirely of the “/” character
- A pointer to the string “.”
- If path is a NULL pointer, or points to an
empty string
Together the
dirname()
and basename() functions yield a complete pathname.
The expression dirname(path) obtains the
pathname of the directory where basename(path)
is found.
|
The basename() function might modify the string pointed to by
path, and can return a pointer to static storage. |
A pointer to the final component of path.
#include <stdio.h>
#include <libgen.h>
#include <stdlib.h>
int main( int argc, char** argv )
{
int x;
for( x = 1; x < argc; x++ ) {
printf( "%s\n", basename( argv[x] ) );
}
return EXIT_SUCCESS;
}
The table below shows the output of the program, given the input:
Input |
Output |
“/usr/lib” |
“lib” |
“/usr/” |
“usr” |
“/” |
“/” |
POSIX 1003.1 XSI
Safety: | |
Cancellation point |
No |
Interrupt handler |
Yes |
Signal handler |
Yes |
Thread |
Yes |
dirname()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/b/basename.html on line 191
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/b/basename.html on line 191