1 /* basename.c - Return non-directory portion of a pathname 2 * 3 * Copyright 2012 Tryn Mirell <tryn (at) mirell.org> 4 * 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/basename.html 6 7 8 USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_USR|TOYFLAG_BIN)) 9 10 config BASENAME 11 bool "basename" 12 default y 13 help 14 usage: basename string [suffix] 15 16 Return non-directory portion of a pathname removing suffix 17 */ 18 19 #include "toys.h" 20 21 void basename_main(void) 22 { 23 char *base = basename(*toys.optargs), *suffix = toys.optargs[1]; 24 25 // chop off the suffix if provided 26 if (suffix && *suffix && (suffix = strend(base, suffix))) *suffix = 0; 27 28 puts(base); 29 } 30