find: improve usage text (Natanael Copa <natanael.copa@gmail.com>)
[oweals/busybox.git] / coreutils / rm.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Mini rm implementation for busybox
4  *
5  * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8  */
9
10 /* BB_AUDIT SUSv3 compliant */
11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
12
13 /* Mar 16, 2003      Manuel Novoa III   (mjn3@codepoet.org)
14  *
15  * Size reduction.
16  */
17
18 #include <unistd.h>
19 #include "busybox.h"
20
21 int rm_main(int argc, char **argv);
22 int rm_main(int argc, char **argv)
23 {
24         int status = 0;
25         int flags = 0;
26         unsigned opt;
27
28         opt_complementary = "f-i:i-f";
29         opt = getopt32(argc, argv, "fiRr");
30         if(opt & 1)
31                                 flags |= FILEUTILS_FORCE;
32         if(opt & 2)
33                 flags |= FILEUTILS_INTERACTIVE;
34         if(opt & 12)
35                 flags |= FILEUTILS_RECUR;
36
37         if (*(argv += optind) != NULL) {
38                 do {
39                         const char *base = bb_get_last_path_component(*argv);
40
41                         if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) {
42                                 bb_error_msg("cannot remove '.' or '..'");
43                         } else if (remove_file(*argv, flags) >= 0) {
44                                 continue;
45                         }
46                         status = 1;
47                 } while (*++argv);
48         } else if (!(flags & FILEUTILS_FORCE)) {
49                 bb_show_usage();
50         }
51
52         return status;
53 }