# HG changeset patch # User Rob Landley # Date 1329189185 21600 # Node ID dd24f86d5ad55105a2658caf64f0f24154618cbc # Parent 6c62d5b6675a045b5be848d042c5eb87ef70bcba Minor code cleanup and typo fix. diff -r 6c62d5b6675a -r dd24f86d5ad5 scripts/test/basename.test --- a/scripts/test/basename.test Sun Feb 12 14:14:58 2012 +0100 +++ b/scripts/test/basename.test Mon Feb 13 21:13:05 2012 -0600 @@ -16,8 +16,8 @@ testing "basename suffix=result" "basename .txt .txt" ".txt\n" "" "" # Deal with suffix appearing in the filename -testing "basename reappering suffix 1" "basename a.txt.txt .txt" "a.txt\n" "" "" -testing "basename reappering suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" "" +testing "basename reappearing suffix 1" "basename a.txt.txt .txt" "a.txt\n" "" "" +testing "basename reappearing suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" "" # A suffix should be a real suffix, only a the end. -testing "basename invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" "" \ No newline at end of file +testing "basename invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" "" diff -r 6c62d5b6675a -r dd24f86d5ad5 toys/basename.c --- a/toys/basename.c Sun Feb 12 14:14:58 2012 +0100 +++ b/toys/basename.c Mon Feb 13 21:13:05 2012 -0600 @@ -37,10 +37,8 @@ // chop off the suffix if provided if (suffix) { - int suflen = strlen(suffix); - int reslen = strlen(base); - if (suflen < reslen && !strcmp( base+reslen-suflen, suffix)) - base[reslen-suflen] = 0; + arg = base + strlen(base) - strlen(suffix); + if (arg > base && !strcmp(arg, suffix)) *arg = 0; } puts(base);