basename: Ignore suffix when its an empty string - sbase - suckless unix tools
 (HTM) git clone git://git.suckless.org/sbase
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 61b58e3c2731966a8fa4d60e33a724a27e722f76
 (DIR) parent fdcca1be51cad2c0b53d41d829830c1a7070def0
 (HTM) Author: Carlos J. Torres <vlaadbrain@gmail.com>
       Date:   Mon,  3 Nov 2025 10:10:31 -0500
       
       basename: Ignore suffix when its an empty string
       
       basename(3) manual states if path is a null pointer or emtpy
       string, a pointer to "." is returned. We shouldn't attempt
       to modify it because its const.
       
       Diffstat:
         M basename.c                          |       5 +++--
       
       1 file changed, 3 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/basename.c b/basename.c
       @@ -15,6 +15,7 @@ int
        main(int argc, char *argv[])
        {
                ssize_t off;
       +        size_t slen;
                char *p;
        
                ARGBEGIN {
       @@ -26,8 +27,8 @@ main(int argc, char *argv[])
                        usage();
        
                p = basename(argv[0]);
       -        if (argc == 2) {
       -                off = strlen(p) - strlen(argv[1]);
       +        if (argc == 2 && (slen = strlen(argv[1])) > 0) {
       +                off = strlen(p) - slen;
                        if (off > 0 && !strcmp(p + off, argv[1]))
                                p[off] = '\0';
                }