Rev | Line | |
---|
[821] | 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 | *
|
---|
[1765] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
[821] | 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 |
|
---|
[1765] | 18 | #include "libbb.h"
|
---|
[821] | 19 |
|
---|
[1765] | 20 | /* This is a NOFORK applet. Be very careful! */
|
---|
| 21 |
|
---|
| 22 | int rm_main(int argc, char **argv);
|
---|
[821] | 23 | int rm_main(int argc, char **argv)
|
---|
| 24 | {
|
---|
| 25 | int status = 0;
|
---|
| 26 | int flags = 0;
|
---|
[1765] | 27 | unsigned opt;
|
---|
[821] | 28 |
|
---|
[1765] | 29 | opt_complementary = "f-i:i-f";
|
---|
| 30 | opt = getopt32(argv, "fiRr");
|
---|
| 31 | argv += optind;
|
---|
| 32 | if (opt & 1)
|
---|
| 33 | flags |= FILEUTILS_FORCE;
|
---|
| 34 | if (opt & 2)
|
---|
[821] | 35 | flags |= FILEUTILS_INTERACTIVE;
|
---|
[1765] | 36 | if (opt & 12)
|
---|
[821] | 37 | flags |= FILEUTILS_RECUR;
|
---|
| 38 |
|
---|
[1765] | 39 | if (*argv != NULL) {
|
---|
[821] | 40 | do {
|
---|
| 41 | const char *base = bb_get_last_path_component(*argv);
|
---|
| 42 |
|
---|
[1765] | 43 | if (DOT_OR_DOTDOT(base)) {
|
---|
| 44 | bb_error_msg("cannot remove '.' or '..'");
|
---|
[821] | 45 | } else if (remove_file(*argv, flags) >= 0) {
|
---|
| 46 | continue;
|
---|
| 47 | }
|
---|
| 48 | status = 1;
|
---|
| 49 | } while (*++argv);
|
---|
| 50 | } else if (!(flags & FILEUTILS_FORCE)) {
|
---|
| 51 | bb_show_usage();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | return status;
|
---|
| 55 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.