Mercurial > hg > toybox
changeset 405:a8b14410e784
'basename': Handle where we have no / passed
author | Tryn Mirell <tryn@mirell.org> |
---|---|
date | Sun, 15 Jan 2012 23:27:22 -0600 |
parents | ad5ffc45aa62 |
children | c8a3d740c229 |
files | toys/basename.c |
diffstat | 1 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 = "/";