mirror of
git://git.suckless.org/sbase
synced 2026-01-26 13:43:17 +00:00
POSIX explicitely mandates to ignore . or .. to avoid pitfals like rm -r .* and no having files that begin with a dot.
48 lines
743 B
C
48 lines
743 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
|
|
#include "fs.h"
|
|
#include "util.h"
|
|
|
|
static void
|
|
usage(void)
|
|
{
|
|
eprintf("usage: %s [-f] [-iRr] file ...\n", argv0);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
struct recursor r = { .fn = rm, .maxdepth = 1, .follow = 'P' };
|
|
|
|
ARGBEGIN {
|
|
case 'f':
|
|
r.flags |= SILENT | IGNORE;
|
|
break;
|
|
case 'i':
|
|
r.flags |= CONFIRM;
|
|
break;
|
|
case 'R':
|
|
case 'r':
|
|
r.maxdepth = 0;
|
|
break;
|
|
default:
|
|
usage();
|
|
} ARGEND
|
|
|
|
if (!argc) {
|
|
if (!(r.flags & IGNORE))
|
|
usage();
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
for (; *argv; argc--, argv++) {
|
|
if (strcmp(*argv, ".") && strcmp(*argv, ".."))
|
|
recurse(AT_FDCWD, *argv, NULL, &r);
|
|
}
|
|
|
|
return rm_status || recurse_status;
|
|
}
|