| 1 |
/* |
| 2 |
* FILE: basename.c |
| 3 |
* PURPOSE: a reimplementation of BSD's basename so that it can also be |
| 4 |
* used as a function in other programs (see filenames.c and |
| 5 |
* filenames.h) |
| 6 |
* AUTHOR: Piet Tutelaers |
| 7 |
* VERSION: 1.0 (Sept. 1995) |
| 8 |
*/ |
| 9 |
#include <stdlib.h> /* exit() */ |
| 10 |
#include <stdio.h> /* printf() */ |
| 11 |
#include "basics.h" /* fatal() */ |
| 12 |
#include "filenames.h" /* basename() */ |
| 13 |
|
| 14 |
int main(int argc, char **argv) |
| 15 |
{ |
| 16 |
if (argc < 2 || argc > 3) |
| 17 |
fatal("Usage: basename string [suffix]\n"); |
| 18 |
|
| 19 |
if (argc == 2) |
| 20 |
printf("%s\n", basename(argv[1], NULL)); |
| 21 |
else |
| 22 |
printf("%s\n", basename(argv[1], argv[2])); |
| 23 |
exit(0); |
| 24 |
} |