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