Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame^] | 1 | #include "internal.h" |
| 2 | #include <errno.h> |
| 3 | |
| 4 | const char rm_usage[] = "rm [-r] file [file ...]\n" |
| 5 | "\n" |
| 6 | "\tDelete files.\n" |
| 7 | "\n" |
| 8 | "\t-r:\tRecursively remove files and directories.\n"; |
| 9 | |
| 10 | extern int |
| 11 | rm_main(struct FileInfo * i, int argc, char * * argv) |
| 12 | { |
| 13 | i->processDirectoriesAfterTheirContents = 1; |
| 14 | return monadic_main(i, argc, argv); |
| 15 | } |
| 16 | |
| 17 | extern int |
| 18 | rm_fn(const struct FileInfo * i) |
| 19 | { |
| 20 | if ( i->recursive |
| 21 | && !i->isSymbolicLink |
| 22 | && (i->stat.st_mode & S_IFMT) == S_IFDIR ) |
| 23 | return rmdir_fn(i); |
| 24 | else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) { |
| 25 | name_and_error(i->source); |
| 26 | return 1; |
| 27 | } |
| 28 | else |
| 29 | return 0; |
| 30 | } |