Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 3 | * Mini dirname implementation for busybox |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 9 | //config:config DIRNAME |
| 10 | //config: bool "dirname" |
| 11 | //config: default y |
| 12 | //config: help |
| 13 | //config: dirname is used to strip a non-directory suffix from |
| 14 | //config: a file name. |
| 15 | |
| 16 | //applet:IF_DIRNAME(APPLET_NOFORK(dirname, dirname, BB_DIR_USR_BIN, BB_SUID_DROP, dirname)) |
| 17 | |
| 18 | //kbuild:lib-$(CONFIG_DIRNAME) += dirname.o |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 19 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 20 | /* BB_AUDIT SUSv3 compliant */ |
| 21 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */ |
Mark Whitley | 827e45c | 2001-03-09 23:59:51 +0000 | [diff] [blame] | 22 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 23 | //usage:#define dirname_trivial_usage |
| 24 | //usage: "FILENAME" |
| 25 | //usage:#define dirname_full_usage "\n\n" |
| 26 | //usage: "Strip non-directory suffix from FILENAME" |
| 27 | //usage: |
| 28 | //usage:#define dirname_example_usage |
| 29 | //usage: "$ dirname /tmp/foo\n" |
| 30 | //usage: "/tmp\n" |
| 31 | //usage: "$ dirname /tmp/foo/\n" |
| 32 | //usage: "/tmp\n" |
| 33 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 34 | #include "libbb.h" |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 35 | |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 36 | /* This is a NOFORK applet. Be very careful! */ |
| 37 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 38 | int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 39 | int dirname_main(int argc UNUSED_PARAM, char **argv) |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 40 | { |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 41 | puts(dirname(single_argv(argv))); |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 42 | return fflush_all(); |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 43 | } |