aboutsummaryrefslogtreecommitdiff
path: root/coreutils/rm.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/rm.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'coreutils/rm.c')
-rw-r--r--coreutils/rm.c67
1 files changed, 31 insertions, 36 deletions
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 51c9f4ceb..5489350e5 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -2,7 +2,6 @@
2/* 2/*
3 * Mini rm implementation for busybox 3 * Mini rm implementation for busybox
4 * 4 *
5 *
6 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> 5 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
7 * 6 *
8 * 7 *
@@ -22,55 +21,51 @@
22 * 21 *
23 */ 22 */
24 23
25#include <stdio.h> 24/* BB_AUDIT SUSv3 compliant */
26#include <time.h> 25/* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
27#include <utime.h> 26
28#include <dirent.h> 27/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
29#include <errno.h> 28 *
29 * Size reduction.
30 */
31
30#include <unistd.h> 32#include <unistd.h>
31#include <stdlib.h>
32#include <string.h>
33#include <getopt.h>
34#include "busybox.h" 33#include "busybox.h"
35 34
36extern int rm_main(int argc, char **argv) 35extern int rm_main(int argc, char **argv)
37{ 36{
38 int status = 0; 37 int status = 0;
39 int opt;
40 int flags = 0; 38 int flags = 0;
41 int i; 39 int opt;
42 40
43 while ((opt = getopt(argc, argv, "fiRr")) != -1) { 41 while ((opt = getopt(argc, argv, "fiRr")) > 0) {
44 switch (opt) { 42 if ((opt == 'r') || (opt == 'R')) {
45 case 'f':
46 flags &= ~FILEUTILS_INTERACTIVE;
47 flags |= FILEUTILS_FORCE;
48 break;
49 case 'i':
50 flags &= ~FILEUTILS_FORCE;
51 flags |= FILEUTILS_INTERACTIVE;
52 break;
53 case 'R':
54 case 'r':
55 flags |= FILEUTILS_RECUR; 43 flags |= FILEUTILS_RECUR;
56 break; 44 } else {
45 flags &= ~(FILEUTILS_INTERACTIVE | FILEUTILS_FORCE);
46 if (opt == 'i') {
47 flags |= FILEUTILS_INTERACTIVE;
48 } else if (opt == 'f') {
49 flags |= FILEUTILS_FORCE;
50 } else {
51 bb_show_usage();
52 }
57 } 53 }
58 } 54 }
59 55
60 if (!(flags & FILEUTILS_FORCE) && optind == argc) 56 if (*(argv += optind) != NULL) {
61 show_usage(); 57 do {
62 58 const char *base = bb_get_last_path_component(*argv);
63 for (i = optind; i < argc; i++) {
64 char *base = get_last_path_component(argv[i]);
65
66 if (strcmp(base, ".") == 0 || strcmp(base, "..") == 0) {
67 error_msg("cannot remove `.' or `..'");
68 status = 1;
69 continue;
70 }
71 59
72 if (remove_file(argv[i], flags) < 0) 60 if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) {
61 bb_error_msg("cannot remove `.' or `..'");
62 } else if (remove_file(*argv, flags) >= 0) {
63 continue;
64 }
73 status = 1; 65 status = 1;
66 } while (*++argv);
67 } else if (!(flags & FILEUTILS_FORCE)) {
68 bb_show_usage();
74 } 69 }
75 70
76 return status; 71 return status;