view toys/basename.c @ 198:3227c5316260

Update links and add some more spec comments.
author Rob Landley <rob@landley.net>
date Tue, 11 Dec 2007 15:41:31 -0600
parents 25447caf1b4b
children d4176f3f3835
line wrap: on
line source

/* vi: set sw=4 ts=4: */
/* basename.c - print non-directory portion of path
 *
 * See http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html
 */

#include "toys.h"

void basename_main(void)
{
	char *name = basename(*toys.optargs);
	char *suffix = toys.optargs[1];
	if (suffix) {
		char *end = name+strlen(name)-strlen(suffix);
		if (end>name && !strcmp(end,suffix)) *end=0;
	}
	puts(name);
}