Files
sbase/rm.c
T

43 lines
676 B
C
Raw Normal View History

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