2008-11-19 05:47:44 +08:00
|
|
|
#ifndef _NO_BASENAME
|
2005-04-09 04:48:40 +08:00
|
|
|
/* Copyright 2005 Shaun Jackman
|
|
|
|
* Permission to use, copy, modify, and distribute this software
|
|
|
|
* is freely granted, provided that this notice is preserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
char*
|
2017-12-04 11:43:30 +08:00
|
|
|
basename (char *path)
|
2005-04-09 04:48:40 +08:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
if( path == NULL || *path == '\0' )
|
|
|
|
return ".";
|
|
|
|
p = path + strlen(path) - 1;
|
|
|
|
while( *p == '/' ) {
|
|
|
|
if( p == path )
|
|
|
|
return path;
|
|
|
|
*p-- = '\0';
|
|
|
|
}
|
|
|
|
while( p >= path && *p != '/' )
|
|
|
|
p--;
|
|
|
|
return p + 1;
|
|
|
|
}
|
2008-11-19 05:47:44 +08:00
|
|
|
|
|
|
|
#endif /* !_NO_BASENAME */
|