Rev 3386 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
Line 31... | Line 31... | ||
31 | #include <stdio.h> |
31 | #include <stdio.h> |
32 | #include <stdlib.h> |
32 | #include <stdlib.h> |
33 | #include <unistd.h> |
33 | #include <unistd.h> |
34 | #include <fcntl.h> |
34 | #include <fcntl.h> |
35 | #include <dirent.h> |
35 | #include <dirent.h> |
36 | #include <assert.h> |
- | |
37 | #include <getopt.h> |
36 | #include <getopt.h> |
38 | 37 | ||
39 | #include "config.h" |
38 | #include "config.h" |
40 | #include "errors.h" |
39 | #include "errors.h" |
41 | #include "util.h" |
40 | #include "util.h" |
Line 142... | Line 141... | ||
142 | 141 | ||
143 | return RM_BOGUS; |
142 | return RM_BOGUS; |
144 | } |
143 | } |
145 | 144 | ||
146 | /* Dispays help for rm in various levels */ |
145 | /* Dispays help for rm in various levels */ |
147 | void * help_cmd_rm(unsigned int level) |
146 | void help_cmd_rm(unsigned int level) |
148 | { |
147 | { |
149 | if (level == HELP_SHORT) { |
148 | if (level == HELP_SHORT) { |
150 | printf("`%s' removes files and directories.\n", cmdname); |
149 | printf("`%s' removes files and directories.\n", cmdname); |
151 | } else { |
150 | } else { |
152 | help_cmd_rm(HELP_SHORT); |
151 | help_cmd_rm(HELP_SHORT); |
Line 159... | Line 158... | ||
159 | " -f, --force Do not prompt prior to removing files\n" |
158 | " -f, --force Do not prompt prior to removing files\n" |
160 | " -s, --safe Stop if directories change during removal\n\n" |
159 | " -s, --safe Stop if directories change during removal\n\n" |
161 | "Currently, %s is under development, some options don't work.\n", |
160 | "Currently, %s is under development, some options don't work.\n", |
162 | cmdname, cmdname); |
161 | cmdname, cmdname); |
163 | } |
162 | } |
164 | return CMD_VOID; |
163 | return; |
165 | } |
164 | } |
166 | 165 | ||
167 | /* Main entry point for rm, accepts an array of arguments */ |
166 | /* Main entry point for rm, accepts an array of arguments */ |
168 | int * cmd_rm(char **argv) |
167 | int cmd_rm(char **argv) |
169 | { |
168 | { |
170 | unsigned int argc; |
169 | unsigned int argc; |
171 | unsigned int i, scope, ret = 0; |
170 | unsigned int i, scope, ret = 0; |
172 | int c, opt_ind; |
171 | int c, opt_ind; |
173 | size_t len; |
172 | size_t len; |
Line 217... | Line 216... | ||
217 | 216 | ||
218 | i = optind; |
217 | i = optind; |
219 | while (NULL != argv[i]) { |
218 | while (NULL != argv[i]) { |
220 | len = strlen(argv[i]) + 2; |
219 | len = strlen(argv[i]) + 2; |
221 | buff = (char *) realloc(buff, len); |
220 | buff = (char *) realloc(buff, len); |
222 | assert(buff != NULL); |
221 | if (buff == NULL) { |
- | 222 | printf("rm: out of memory\n"); |
|
- | 223 | ret = 1; |
|
- | 224 | break; |
|
- | 225 | } |
|
223 | memset(buff, 0, sizeof(buff)); |
226 | memset(buff, 0, sizeof(buff)); |
224 | snprintf(buff, len, argv[i]); |
227 | snprintf(buff, len, argv[i]); |
225 | 228 | ||
226 | scope = rm_scope(buff); |
229 | scope = rm_scope(buff); |
227 | switch (scope) { |
230 | switch (scope) { |