sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

rm.c (615B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <fcntl.h>
      3 
      4 #include "fs.h"
      5 #include "util.h"
      6 
      7 static void
      8 usage(void)
      9 {
     10 	eprintf("usage: %s [-f] [-Rr] file ...\n", argv0);
     11 }
     12 
     13 int
     14 main(int argc, char *argv[])
     15 {
     16 	struct recursor r = { .fn = rm, .maxdepth = 1, .follow = 'P' };
     17 
     18 	ARGBEGIN {
     19 	case 'f':
     20 		r.flags |= SILENT;
     21 		break;
     22 	case 'R':
     23 	case 'r':
     24 		r.maxdepth = 0;
     25 		break;
     26 	default:
     27 		usage();
     28 	} ARGEND
     29 
     30 	if (!argc) {
     31 		if (!(r.flags & SILENT))
     32 			usage();
     33 		else
     34 			return 0;
     35 	}
     36 
     37 	for (; *argv; argc--, argv++)
     38 		recurse(AT_FDCWD, *argv, NULL, &r);
     39 
     40 	return rm_status || recurse_status;
     41 }