about summary refs log tree commit diff
path: root/src/misc/basename.c
blob: c87e00cdcdd9b76228f842a9429fb967f40da42b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
#include <string.h>
#include <libgen.h>

char *basename(char *s)
{
	size_t i;
	if (!s || !*s) return ".";
	i = strlen(s)-1;
	for (; i&&s[i]=='/'; i--) s[i] = 0;
	for (; i&&s[i-1]!='/'; i--);
	return s+i;
}