mirror of
https://github.com/sheumann/hush.git
synced 2025-01-15 18:30:43 +00:00
Patch from Matt Kraai to fix 'dirname /'
This commit is contained in:
parent
4d4b3b1d88
commit
483262f633
@ -32,13 +32,14 @@ extern int dirname_main(int argc, char **argv)
|
|||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
s=*argv+strlen(*argv)-1;
|
s=*argv+strlen(*argv)-1;
|
||||||
while (s && *s == '/') {
|
while (s != *argv && *s == '/') {
|
||||||
*s = '\0';
|
*s-- = '\0';
|
||||||
s=*argv+strlen(*argv)-1;
|
|
||||||
}
|
}
|
||||||
s = strrchr(*argv, '/');
|
s = strrchr(*argv, '/');
|
||||||
if (s && *s)
|
if (s != NULL && s == *argv)
|
||||||
|
s[1] = '\0';
|
||||||
|
else if (s != NULL)
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
printf("%s\n", (s)? *argv : ".");
|
puts(s ? *argv : ".");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
11
dirname.c
11
dirname.c
@ -32,13 +32,14 @@ extern int dirname_main(int argc, char **argv)
|
|||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
s=*argv+strlen(*argv)-1;
|
s=*argv+strlen(*argv)-1;
|
||||||
while (s && *s == '/') {
|
while (s != *argv && *s == '/') {
|
||||||
*s = '\0';
|
*s-- = '\0';
|
||||||
s=*argv+strlen(*argv)-1;
|
|
||||||
}
|
}
|
||||||
s = strrchr(*argv, '/');
|
s = strrchr(*argv, '/');
|
||||||
if (s && *s)
|
if (s != NULL && s == *argv)
|
||||||
|
s[1] = '\0';
|
||||||
|
else if (s != NULL)
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
printf("%s\n", (s)? *argv : ".");
|
puts(s ? *argv : ".");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user