1 #ifndef _NO_BASENAME 2 /* Copyright 2005 Shaun Jackman 3 * Permission to use, copy, modify, and distribute this software 4 * is freely granted, provided that this notice is preserved. 5 */ 6 7 #include <libgen.h> 8 #include <string.h> 9 10 char* basename(char * path)11basename (char *path) 12 { 13 char *p; 14 if( path == NULL || *path == '\0' ) 15 return "."; 16 p = path + strlen(path) - 1; 17 while( *p == '/' ) { 18 if( p == path ) 19 return path; 20 *p-- = '\0'; 21 } 22 while( p >= path && *p != '/' ) 23 p--; 24 return p + 1; 25 } 26 27 #endif /* !_NO_BASENAME */ 28