Uninitialized vector entry?
[minix3.git] / lib / other / basename.c
blob5de8f7af5b1ff3642ca068ba51de15adade85a5b
1 /*
2 basename.c
3 */
5 #include <libgen.h>
6 #include <string.h>
8 char *basename(path)
9 char *path;
11 size_t len;
12 char *cp;
14 if (path == NULL)
15 return ".";
16 len= strlen(path);
17 if (len == 0)
18 return ".";
19 while (path[len-1] == '/')
21 if (len == 1)
22 return path; /* just "/" */
23 len--;
24 path[len]= '\0';
26 cp= strrchr(path, '/');
27 if (cp != NULL)
28 return cp+1;
29 return path;