projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Support for tar -z option for uncompressing only
[oweals/busybox.git]
/
basename.c
diff --git
a/basename.c
b/basename.c
index efd07e27207f5231bd6b2adfc8c28d46712301f4..fcc7d4619ec458fbbddaf88e63605aa385f3d78b 100644
(file)
--- a/
basename.c
+++ b/
basename.c
@@
-21,29
+21,29
@@
*
*/
*
*/
-#include "
internal
.h"
+#include "
busybox
.h"
#include <stdio.h>
extern int basename_main(int argc, char **argv)
{
#include <stdio.h>
extern int basename_main(int argc, char **argv)
{
- char* s, *s1;
+ int m, n;
+ char *s;
if ((argc < 2) || (**(argv + 1) == '-')) {
if ((argc < 2) || (**(argv + 1) == '-')) {
- usage("basename [FILE ...]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
- "\nStrips directory path and suffixes from FILE(s).\n"
-#endif
- );
+ usage(basename_usage);
}
}
+
argv++;
argv++;
- s1=*argv+strlen(*argv)-1;
- while (s1 && *s1 == '/') {
- *s1 = '\0';
- s1=*argv+strlen(*argv)-1;
+ s = get_last_path_component(*argv);
+
+ if (argc>2) {
+ argv++;
+ n = strlen(*argv);
+ m = strlen(s);
+ if (m>=n && strncmp(s+m-n, *argv, n)==0)
+ s[m-n] = '\0';
}
}
- s = strrchr(*argv, '/');
- printf("%s\n", (s)? s + 1 : *argv);
- exit(TRUE);
+ printf("%s\n", s);
+ return EXIT_SUCCESS;
}
}
-