sbase/libutil/rm.c
FRIGN 9fd4a745f8 Add history and config-struct to recurse
For loop detection, a history is mandatory. In the process of also
adding a flexible struct to recurse, the recurse-definition was moved
to fs.h.
The motivation behind the struct is to allow easy extensions to the
recurse-function without having to change the prototypes of all
functions in the process.
Adding flags is really simple as well now.

Using the recursor-struct, it's also easier to see which defaults
apply to a program (for instance, which type of follow, ...).

Another change was to add proper stat-lstat-usage in recurse. It
was wrong before.
2015-03-13 00:29:48 +01:00

24 lines
431 B
C

/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdio.h>
#include "../fs.h"
#include "../util.h"
int rm_fflag = 0;
int rm_rflag = 0;
int rm_status = 0;
void
rm(const char *path, void *data, struct recursor *r)
{
if (rm_rflag)
recurse(path, NULL, r);
if (remove(path) < 0) {
if (!rm_fflag)
weprintf("remove %s:", path);
if (!(rm_fflag && errno == ENOENT))
rm_status = 1;
}
}