changeset 456:dd24f86d5ad5

Minor code cleanup and typo fix.
author Rob Landley <rob@landley.net>
date Mon, 13 Feb 2012 21:13:05 -0600
parents 6c62d5b6675a
children 521d54da4d0c
files scripts/test/basename.test toys/basename.c
diffstat 2 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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" "" ""
--- 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);