sbase/rm.c

36 lines
660 B
C
Raw Normal View History

2011-05-24 00:52:28 +00:00
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
2012-01-30 22:41:33 +00:00
#include <sys/stat.h>
#include "fs.h"
2011-05-24 00:52:28 +00:00
#include "util.h"
int
main(int argc, char *argv[])
{
char c;
2012-01-30 22:41:33 +00:00
struct stat st;
2011-05-24 00:52:28 +00:00
while((c = getopt(argc, argv, "fr")) != -1)
switch(c) {
case 'f':
2012-01-30 22:41:33 +00:00
rm_fflag = true;
2011-05-24 00:52:28 +00:00
break;
case 'r':
2012-01-30 22:41:33 +00:00
rm_rflag = true;
2011-05-24 00:52:28 +00:00
break;
default:
exit(EXIT_FAILURE);
}
2012-01-30 22:41:33 +00:00
for(; optind < argc; optind++) {
if(!rm_rflag && stat(argv[optind], &st) == 0 &&
S_ISDIR(st.st_mode))
fprintf(stderr, "%s: is a directory\n", argv[optind]);
else
rm(argv[optind]);
}
2011-05-24 00:52:28 +00:00
return EXIT_SUCCESS;
}