blob: dc35b0297ea095ebb904d2288aef4c571d73d067 [file] [log] [blame]
Eric Andersencc8ed391999-10-05 16:24:54 +00001#include "internal.h"
2#include <errno.h>
3
4const 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
10extern int
11rm_main(struct FileInfo * i, int argc, char * * argv)
12{
13 i->processDirectoriesAfterTheirContents = 1;
14 return monadic_main(i, argc, argv);
15}
16
17extern int
18rm_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}