--- basename.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/basename.c b/basename.c index 402be17..b4c451f 100644 --- a/basename.c +++ b/basename.c _AT_@ -18,6 +18,7 @@ int main(int argc, char *argv[]) { char *s, *p; + size_t d; ARGBEGIN { default: _AT_@ -28,10 +29,13 @@ main(int argc, char *argv[]) usage(); s = basename(argv[0]); - if (argc == 2) { - p = strstr(s, argv[1]); - if (p && p[strlen(p)] == '\0') - *p = '\0'; + if (argc == 2 && *s != '/') { + d = strlen(argv[0]) - strlen(argv[1]); + if (d >= 0) { + p = argv[0] + d; + if (strcmp(p, argv[1]) == 0) + *p = '\0'; + } } puts(s); return 0; -- 2.1.3Received on Wed Dec 03 2014 - 23:37:16 CET
This archive was generated by hypermail 2.3.0 : Wed Dec 03 2014 - 23:48:07 CET