aboutsummaryrefslogtreecommitdiff
path: root/toys/basename.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-11-27 00:57:42 -0600
committerRob Landley <rob@landley.net>2007-11-27 00:57:42 -0600
commitc15b3edf55ebd915b234e2ee6280a19874a052f9 (patch)
tree43d6c9c5bce6f6b7200ebb0aa84479248d1596b5 /toys/basename.c
parent57389ec1d8f5b32e5de97f0f557e5f5c5b7054bb (diff)
downloadtoybox-c15b3edf55ebd915b234e2ee6280a19874a052f9.tar.gz
Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Diffstat (limited to 'toys/basename.c')
-rw-r--r--toys/basename.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/toys/basename.c b/toys/basename.c
new file mode 100644
index 00000000..2ea6882c
--- /dev/null
+++ b/toys/basename.c
@@ -0,0 +1,15 @@
+#include "toys.h"
+
+int basename_main(void)
+{
+ char *name = basename(toys.optargs[0]);
+ if (toys.optargs[1]) {
+ int slen = strlen(toys.optargs[1]);
+ int name_len = strlen(name);
+ if (slen < name_len)
+ if (!strcmp(name+name_len-slen, toys.optargs[1]))
+ *(name+name_len-slen) = '\0';
+ }
+ puts(name);
+ return 0;
+}