aboutsummaryrefslogtreecommitdiff
path: root/toys/basename.c
blob: 2ea6882cda05471be5e5719c056f9bb90425cc0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "toys.h"

int basename_main(void)
{
	char *name = basename(toys.optargs[0]);
	if (toys.optargs[1]) {
		int slen = strlen(toys.optargs[1]);
		int name_len = strlen(name);
		if (slen < name_len)
			if (!strcmp(name+name_len-slen, toys.optargs[1]))
				*(name+name_len-slen) = '\0';
	}
	puts(name);
	return 0;
}