blob: e4e9bb0be48631471db33c38d58717d56aacb214 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersenbed30e91999-10-18 19:02:32 +00002/*
3 * Mini rm implementation for busybox
4 *
Matt Kraai8810bdb2001-04-24 20:04:18 +00005 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
Eric Andersenbed30e91999-10-18 19:02:32 +00006 *
Mark Whitleyf6ba2da2001-03-13 16:35:55 +00007 *
Eric Andersenbed30e91999-10-18 19:02:32 +00008 * 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 cad53642003-03-19 09:13:01 +000024/* 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 Andersened3ef502001-01-27 08:24:39 +000032#include <unistd.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000033#include "busybox.h"
Eric Andersencc8ed391999-10-05 16:24:54 +000034
Eric Andersenbed30e91999-10-18 19:02:32 +000035extern int rm_main(int argc, char **argv)
36{
Matt Kraai8810bdb2001-04-24 20:04:18 +000037 int status = 0;
Matt Kraai8810bdb2001-04-24 20:04:18 +000038 int flags = 0;
Eric Andersen8876fb22003-06-20 09:01:58 +000039 unsigned long opt;
Matt Kraai8810bdb2001-04-24 20:04:18 +000040
"Vladimir N. Oleynik"27421a12005-09-05 14:46:07 +000041 bb_opt_complementally = "f-i:i-f";
Eric Andersen8876fb22003-06-20 09:01:58 +000042 opt = bb_getopt_ulflags(argc, argv, "fiRr");
43 if(opt & 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +000044 flags |= FILEUTILS_FORCE;
Eric Andersen8876fb22003-06-20 09:01:58 +000045 if(opt & 2)
46 flags |= FILEUTILS_INTERACTIVE;
47 if(opt & 12)
48 flags |= FILEUTILS_RECUR;
Matt Kraai8810bdb2001-04-24 20:04:18 +000049
Manuel Novoa III cad53642003-03-19 09:13:01 +000050 if (*(argv += optind) != NULL) {
51 do {
52 const char *base = bb_get_last_path_component(*argv);
Matt Kraai8810bdb2001-04-24 20:04:18 +000053
Manuel Novoa III cad53642003-03-19 09:13:01 +000054 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 Kraai8810bdb2001-04-24 20:04:18 +000059 status = 1;
Manuel Novoa III cad53642003-03-19 09:13:01 +000060 } while (*++argv);
61 } else if (!(flags & FILEUTILS_FORCE)) {
62 bb_show_usage();
Eric Andersena9c95ea1999-11-15 17:33:30 +000063 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000064
Matt Kraaid27753a2000-12-05 05:11:41 +000065 return status;
Eric Andersencc8ed391999-10-05 16:24:54 +000066}