gno/usr.orca.bin/describe/basename.c

31 lines
512 B
C
Raw Normal View History

#pragma optimize -1
#include <string.h>
#include <stdio.h>
#include <unistd.h>
char *basename (char *name) {
char *p, brk;
/* checking for ':' is GS-specific */
brk = (strchr(name,':')) ? ':' : '/';
p = strrchr(name,brk);
return ((p) ? p+1 : name);
}
#ifdef SHELLCOMD
int main (int argc, char **argv) {
if (argc != 2) {
fprintf(stderr,"Usage: basename file_name\nVersion 1.0\n");
return -1;
}
printf("%s\n",basename(argv[1]));
return 0;
}
#endif /* SHELLCOMD */