Add one-line GPL boilerplate to numerous (but not all yet) source files.
[platform/upstream/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 {
23         int status = 0;
24         int flags = 0;
25         unsigned long opt;
26
27         bb_opt_complementally = "f-i:i-f";
28         opt = bb_getopt_ulflags(argc, argv, "fiRr");
29         if(opt & 1)
30                                 flags |= FILEUTILS_FORCE;
31         if(opt & 2)
32                 flags |= FILEUTILS_INTERACTIVE;
33         if(opt & 12)
34                 flags |= FILEUTILS_RECUR;
35
36         if (*(argv += optind) != NULL) {
37                 do {
38                         const char *base = bb_get_last_path_component(*argv);
39
40                         if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) {
41                                 bb_error_msg("cannot remove `.' or `..'");
42                         } else if (remove_file(*argv, flags) >= 0) {
43                                 continue;
44                         }
45                         status = 1;
46                 } while (*++argv);
47         } else if (!(flags & FILEUTILS_FORCE)) {
48                 bb_show_usage();
49         }
50
51         return status;
52 }