2011-05-23 20:52:28 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2019-12-22 16:53:46 -05:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-01-30 17:41:33 -05:00
|
|
|
#include "fs.h"
|
2011-05-23 20:52:28 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
2013-06-14 14:20:47 -04:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-02-19 09:54:12 -05:00
|
|
|
eprintf("usage: %s [-f] [-Rr] file ...\n", argv0);
|
2013-06-14 14:20:47 -04:00
|
|
|
}
|
|
|
|
|
2011-05-23 20:52:28 -04:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2020-06-23 05:11:52 -04:00
|
|
|
struct recursor r = { .fn = rm, .maxdepth = 1, .follow = 'P' };
|
2015-03-12 19:25:32 -04:00
|
|
|
|
2013-06-14 14:20:47 -04:00
|
|
|
ARGBEGIN {
|
|
|
|
case 'f':
|
2015-04-19 08:00:47 -04:00
|
|
|
r.flags |= SILENT;
|
2013-06-14 14:20:47 -04:00
|
|
|
break;
|
2013-12-12 08:15:07 -05:00
|
|
|
case 'R':
|
2013-06-14 14:20:47 -04:00
|
|
|
case 'r':
|
2015-04-18 16:04:49 -04:00
|
|
|
r.maxdepth = 0;
|
2013-06-14 14:20:47 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
2015-11-01 05:16:49 -05:00
|
|
|
} ARGEND
|
2013-08-31 18:04:49 -04:00
|
|
|
|
2015-02-28 15:30:20 -05:00
|
|
|
if (!argc) {
|
2015-04-19 08:00:47 -04:00
|
|
|
if (!(r.flags & SILENT))
|
2014-07-04 09:50:20 -04:00
|
|
|
usage();
|
|
|
|
else
|
2014-10-02 18:46:04 -04:00
|
|
|
return 0;
|
2014-07-04 09:50:20 -04:00
|
|
|
}
|
2013-08-31 18:04:49 -04:00
|
|
|
|
2015-03-02 08:19:26 -05:00
|
|
|
for (; *argv; argc--, argv++)
|
2019-12-22 16:53:46 -05:00
|
|
|
recurse(AT_FDCWD, *argv, NULL, &r);
|
2011-05-23 20:52:28 -04:00
|
|
|
|
2015-03-12 19:25:32 -04:00
|
|
|
return rm_status || recurse_status;
|
2011-05-23 20:52:28 -04:00
|
|
|
}
|