sbase/rm.c

42 lines
666 B
C
Raw Normal View History

2011-05-23 20:52:28 -04:00
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
static void rm(const char *);
2011-05-24 07:32:33 -04:00
static bool fflag = false;
static bool rflag = false;
2011-05-23 20:52:28 -04:00
int
main(int argc, char *argv[])
{
char c;
while((c = getopt(argc, argv, "fr")) != -1)
switch(c) {
case 'f':
2011-05-24 07:32:33 -04:00
fflag = true;
2011-05-23 20:52:28 -04:00
break;
case 'r':
rflag = true;
break;
default:
exit(EXIT_FAILURE);
}
for(; optind < argc; optind++)
rm(argv[optind]);
return EXIT_SUCCESS;
}
2011-05-24 19:24:33 -04:00
void
rm(const char *path)
2011-05-23 20:52:28 -04:00
{
2011-05-24 19:24:33 -04:00
if(rflag)
recurse(path, rm);
if(remove(path) != 0 && !fflag)
2011-05-24 07:32:33 -04:00
eprintf("remove %s:", path);
2011-05-23 20:52:28 -04:00
}