source:
tags/syscall-add-simple-foo/minix/lib/other/basename.c@
24
| Last change on this file since 24 was 9, checked in by , 15 years ago | |
|---|---|
| File size: 383 bytes | |
| Line | |
|---|---|
| 1 | /* |
| 2 | basename.c |
| 3 | */ |
| 4 | |
| 5 | #include <libgen.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | char *basename(path) |
| 9 | char *path; |
| 10 | { |
| 11 | size_t len; |
| 12 | char *cp; |
| 13 | |
| 14 | if (path == NULL) |
| 15 | return "."; |
| 16 | len= strlen(path); |
| 17 | if (len == 0) |
| 18 | return "."; |
| 19 | while (path[len-1] == '/') |
| 20 | { |
| 21 | if (len == 1) |
| 22 | return path; /* just "/" */ |
| 23 | len--; |
| 24 | path[len]= '\0'; |
| 25 | } |
| 26 | cp= strrchr(path, '/'); |
| 27 | if (cp != NULL) |
| 28 | return cp+1; |
| 29 | return path; |
| 30 | } |
Note:
See TracBrowser
for help on using the repository browser.