blob: 5aad121b59268bf24069972e7fd3fe25e4986d05 [file] [log] [blame]
Erik Andersenfb002d02000-03-05 08:07:00 +00001/* vi: set sw=4 ts=4: */
2/*
Erik Andersen9cf3bfa2000-04-13 18:49:43 +00003 * Mini dirname implementation for busybox
Erik Andersenfb002d02000-03-05 08:07:00 +00004 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Erik Andersenfb002d02000-03-05 08:07:00 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Erik Andersenfb002d02000-03-05 08:07:00 +00008 */
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +01009//config:config DIRNAME
Denys Vlasenkob097a842018-12-28 03:20:17 +010010//config: bool "dirname (329 bytes)"
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010011//config: default y
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: dirname is used to strip a non-directory suffix from
14//config: a file name.
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010015
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 Andersencbe31da2001-02-20 06:14:08 +000019
Manuel Novoa III cad53642003-03-19 09:13:01 +000020/* BB_AUDIT SUSv3 compliant */
21/* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */
Mark Whitley827e45c2001-03-09 23:59:51 +000022
Pere Orga34425382011-03-31 14:43:25 +020023//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 Vlasenkob6adbf12007-05-26 19:00:18 +000034#include "libbb.h"
Erik Andersenfb002d02000-03-05 08:07:00 +000035
Denis Vlasenko99912ca2007-04-10 15:43:37 +000036/* This is a NOFORK applet. Be very careful! */
37
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000038int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010039int dirname_main(int argc UNUSED_PARAM, char **argv)
Erik Andersenfb002d02000-03-05 08:07:00 +000040{
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010041 puts(dirname(single_argv(argv)));
Denys Vlasenko8131eea2009-11-02 14:19:51 +010042 return fflush_all();
Erik Andersenfb002d02000-03-05 08:07:00 +000043}