# HG changeset patch # User Tryn Mirell # Date 1326691642 21600 # Node ID a8b14410e784eeb954f470e60c9e6ddc4d668684 # Parent ad5ffc45aa62d72318874546bbc0eed9ce4a2e31 'basename': Handle where we have no / passed diff -r ad5ffc45aa62 -r a8b14410e784 toys/basename.c --- a/toys/basename.c Sun Jan 15 23:20:06 2012 -0600 +++ b/toys/basename.c Sun Jan 15 23:27:22 2012 -0600 @@ -26,7 +26,7 @@ if (!arg) return; arglen = strlen(arg); - + // handle the case where we only have single slash if (arglen == 1 && arg[0] == '/') { puts("/"); @@ -39,7 +39,10 @@ } // get everything past the last / - base = strrchr(arg, '/') + 1; + base = strrchr(arg, '/'); + + if (!base) base = arg; + else base++; // handle the case where we have all slashes if (base[0] == 0) base = "/";