mirror of
https://github.com/sheumann/hush.git
synced 2024-11-17 10:07:19 +00:00
17f8418ea7
With FEATURE_VERBOSE off, practically no size change. With it on: function old new delta remove_file 493 556 +63 install_main 719 765 +46 bb_make_directory 383 419 +36 rmdir_main 162 191 +29 copy_file 1516 1544 +28 mv_main 502 525 +23 cmp_main 677 693 +16 bbconfig_config_bz2 5264 5279 +15 mkdir_main 158 168 +10 install_longopts 66 76 +10 rm_main 167 175 +8 nexpr 840 846 +6 scan_tree 275 280 +5 fsck_main 1807 1811 +4 ed_main 2541 2545 +4 expand_one_var 1574 1575 +1 swap_on_off_main 420 418 -2 parse_command 1443 1440 -3 redirect 1279 1274 -5 do_load 946 918 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 16/4 up/down: 304/-38) Total: 266 bytes Based on the patch by Igor Živković. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
69 lines
1.6 KiB
C
69 lines
1.6 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* Mini rm implementation for busybox
|
|
*
|
|
* Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
|
*
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
|
*/
|
|
|
|
/* BB_AUDIT SUSv3 compliant */
|
|
/* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
|
|
|
|
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
|
*
|
|
* Size reduction.
|
|
*/
|
|
|
|
//usage:#define rm_trivial_usage
|
|
//usage: "[-irf] FILE..."
|
|
//usage:#define rm_full_usage "\n\n"
|
|
//usage: "Remove (unlink) FILEs\n"
|
|
//usage: "\n -i Always prompt before removing"
|
|
//usage: "\n -f Never prompt"
|
|
//usage: "\n -R,-r Recurse"
|
|
//usage:
|
|
//usage:#define rm_example_usage
|
|
//usage: "$ rm -rf /tmp/foo\n"
|
|
|
|
#include "libbb.h"
|
|
|
|
/* This is a NOFORK applet. Be very careful! */
|
|
|
|
int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
int rm_main(int argc UNUSED_PARAM, char **argv)
|
|
{
|
|
int status = 0;
|
|
int flags = 0;
|
|
unsigned opt;
|
|
|
|
opt_complementary = "f-i:i-f";
|
|
opt = getopt32(argv, "fiRrv");
|
|
argv += optind;
|
|
if (opt & 1)
|
|
flags |= FILEUTILS_FORCE;
|
|
if (opt & 2)
|
|
flags |= FILEUTILS_INTERACTIVE;
|
|
if (opt & (8|4))
|
|
flags |= FILEUTILS_RECUR;
|
|
if ((opt & 16) && FILEUTILS_VERBOSE)
|
|
flags |= FILEUTILS_VERBOSE;
|
|
|
|
if (*argv != NULL) {
|
|
do {
|
|
const char *base = bb_get_last_path_component_strip(*argv);
|
|
|
|
if (DOT_OR_DOTDOT(base)) {
|
|
bb_error_msg("can't remove '.' or '..'");
|
|
} else if (remove_file(*argv, flags) >= 0) {
|
|
continue;
|
|
}
|
|
status = 1;
|
|
} while (*++argv);
|
|
} else if (!(flags & FILEUTILS_FORCE)) {
|
|
bb_show_usage();
|
|
}
|
|
|
|
return status;
|
|
}
|