Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini rm implementation for busybox |
| 4 | * |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 5 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 6 | * |
Mark Whitley | f6ba2da | 2001-03-13 16:35:55 +0000 | [diff] [blame] | 7 | * |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 24 | /* BB_AUDIT SUSv3 compliant */ |
| 25 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */ |
| 26 | |
| 27 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
| 28 | * |
| 29 | * Size reduction. |
| 30 | */ |
| 31 | |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 32 | #include <unistd.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 33 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 34 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame^] | 35 | int rm_main(int argc, char **argv) |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 36 | { |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 37 | int status = 0; |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 38 | int flags = 0; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 39 | unsigned long opt; |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 40 | |
"Vladimir N. Oleynik" | 27421a1 | 2005-09-05 14:46:07 +0000 | [diff] [blame] | 41 | bb_opt_complementally = "f-i:i-f"; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 42 | opt = bb_getopt_ulflags(argc, argv, "fiRr"); |
| 43 | if(opt & 1) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 44 | flags |= FILEUTILS_FORCE; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 45 | if(opt & 2) |
| 46 | flags |= FILEUTILS_INTERACTIVE; |
| 47 | if(opt & 12) |
| 48 | flags |= FILEUTILS_RECUR; |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 49 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 50 | if (*(argv += optind) != NULL) { |
| 51 | do { |
| 52 | const char *base = bb_get_last_path_component(*argv); |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 53 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 54 | if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) { |
| 55 | bb_error_msg("cannot remove `.' or `..'"); |
| 56 | } else if (remove_file(*argv, flags) >= 0) { |
| 57 | continue; |
| 58 | } |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 59 | status = 1; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 60 | } while (*++argv); |
| 61 | } else if (!(flags & FILEUTILS_FORCE)) { |
| 62 | bb_show_usage(); |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 63 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 64 | |
Matt Kraai | d27753a | 2000-12-05 05:11:41 +0000 | [diff] [blame] | 65 | return status; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 66 | } |