1 /* vi: set sw=4 ts=4: */
3 * Mini rm implementation for busybox
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
9 * INTERACTIVE feature Copyright (C) 2001 by Alcove
10 * written by Christophe Boyanique <Christophe.Boyanique@fr.alcove.com>
11 * for Ipanema Technologies
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 static int recursiveFlag = FALSE;
40 static int forceFlag = FALSE;
41 #ifdef BB_FEATURE_RM_INTERACTIVE
42 static int interactiveFlag = FALSE;
44 static const char *srcName;
47 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
49 #ifdef BB_FEATURE_RM_INTERACTIVE
50 if (interactiveFlag == TRUE) {
51 printf("rm: remove `%s'? ", fileName);
52 if (ask_confirmation() == 0)
56 if (unlink(fileName) < 0) {
57 perror_msg("%s", fileName);
63 static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
65 if (recursiveFlag == FALSE) {
67 perror_msg("%s", fileName);
70 #ifdef BB_FEATURE_RM_INTERACTIVE
71 if (interactiveFlag == TRUE) {
72 printf("rm: remove directory `%s'? ", fileName);
73 if (ask_confirmation() == 0)
77 if (rmdir(fileName) < 0) {
78 perror_msg("%s", fileName);
84 extern int rm_main(int argc, char **argv)
87 int status = EXIT_SUCCESS;
91 /* do normal option parsing */
92 while ((opt = getopt(argc, argv, "Rrf-"
93 #ifdef BB_FEATURE_RM_INTERACTIVE
100 recursiveFlag = TRUE;
104 #ifdef BB_FEATURE_RM_INTERACTIVE
106 interactiveFlag = FALSE;
109 #ifdef BB_FEATURE_RM_INTERACTIVE
111 interactiveFlag = TRUE;
120 if (argc == optind && forceFlag == FALSE) {
124 while (optind < argc) {
125 srcName = argv[optind];
126 if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0
127 && errno == ENOENT) {
128 /* do not reports errors for non-existent files if -f, just skip them */
130 if (recursive_action(srcName, recursiveFlag, FALSE,
131 TRUE, fileAction, dirAction, NULL) == FALSE) {
132 status = EXIT_FAILURE;