Minor code cleanup and typo fix.
authorRob Landley <rob@landley.net>
Tue, 14 Feb 2012 03:13:05 +0000 (21:13 -0600)
committerRob Landley <rob@landley.net>
Tue, 14 Feb 2012 03:13:05 +0000 (21:13 -0600)
scripts/test/basename.test
toys/basename.c

index e0288ce..bd48f4a 100755 (executable)
@@ -16,8 +16,8 @@ testing "basename suffix" "basename a/b/c/d.suffix .suffix" "d\n" "" ""
 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" "" ""
index a6a3bb9..9f228b4 100644 (file)
@@ -37,10 +37,8 @@ void basename_main(void)
     
     // 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);