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 1db885f6214fe306a08bd82584bede039cdf45db..fcc7d4619ec458fbbddaf88e63605aa385f3d78b 100644
(file)
--- a/
basename.c
+++ b/
basename.c
@@
-2,7
+2,7
@@
/*
* Mini basename implementation for busybox
*
/*
* Mini basename implementation for busybox
*
- * Copyright (C) 1999 by Lineo, inc.
+ * Copyright (C) 1999
,2000
by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@
-21,20
+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;
+ int m, n;
+ char *s;
if ((argc < 2) || (**(argv + 1) == '-')) {
if ((argc < 2) || (**(argv + 1) == '-')) {
- usage(
"basename [file ...]\n"
);
+ usage(
basename_usage
);
}
}
+
argv++;
argv++;
- s = strrchr(*argv, '/');
- printf("%s\n", (s)? s + 1 : *argv);
- exit(TRUE);
-}
+ 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';
+ }
+ printf("%s\n", s);
+ return EXIT_SUCCESS;
+}