busybox: update to 1.23.2
[tomato.git] / release / src / router / busybox / coreutils / rm.c
blobd0ad81dfc785160498f907ea19c6b8dc529d73c8
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Mini rm implementation for busybox
5 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
10 /* BB_AUDIT SUSv3 compliant */
11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
13 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
15 * Size reduction.
18 //usage:#define rm_trivial_usage
19 //usage: "[-irf] FILE..."
20 //usage:#define rm_full_usage "\n\n"
21 //usage: "Remove (unlink) FILEs\n"
22 //usage: "\n -i Always prompt before removing"
23 //usage: "\n -f Never prompt"
24 //usage: "\n -R,-r Recurse"
25 //usage:
26 //usage:#define rm_example_usage
27 //usage: "$ rm -rf /tmp/foo\n"
29 #include "libbb.h"
31 /* This is a NOFORK applet. Be very careful! */
33 int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34 int rm_main(int argc UNUSED_PARAM, char **argv)
36 int status = 0;
37 int flags = 0;
38 unsigned opt;
40 opt_complementary = "f-i:i-f";
41 opt = getopt32(argv, "fiRrv");
42 argv += optind;
43 if (opt & 1)
44 flags |= FILEUTILS_FORCE;
45 if (opt & 2)
46 flags |= FILEUTILS_INTERACTIVE;
47 if (opt & (8|4))
48 flags |= FILEUTILS_RECUR;
49 if ((opt & 16) && FILEUTILS_VERBOSE)
50 flags |= FILEUTILS_VERBOSE;
52 if (*argv != NULL) {
53 do {
54 const char *base = bb_get_last_path_component_strip(*argv);
56 if (DOT_OR_DOTDOT(base)) {
57 bb_error_msg("can't remove '.' or '..'");
58 } else if (remove_file(*argv, flags) >= 0) {
59 continue;
61 status = 1;
62 } while (*++argv);
63 } else if (!(flags & FILEUTILS_FORCE)) {
64 bb_show_usage();
67 return status;