sbase

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

rm.c (675B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/stat.h>
      3 
      4 #include <errno.h>
      5 #include <stdio.h>
      6 #include <unistd.h>
      7 
      8 #include "../fs.h"
      9 #include "../util.h"
     10 
     11 int rm_status = 0;
     12 
     13 void
     14 rm(const char *path, struct stat *st, void *data, struct recursor *r)
     15 {
     16 	if (!r->maxdepth && S_ISDIR(st->st_mode)) {
     17 		recurse(path, NULL, r);
     18 
     19 		if (rmdir(path) < 0) {
     20 			if (!(r->flags & SILENT))
     21 				weprintf("rmdir %s:", path);
     22 			if (!((r->flags & SILENT) && errno == ENOENT))
     23 				rm_status = 1;
     24 		}
     25 	} else if (unlink(path) < 0) {
     26 		if (!(r->flags & SILENT))
     27 			weprintf("unlink %s:", path);
     28 		if (!((r->flags & SILENT) && errno == ENOENT))
     29 			rm_status = 1;
     30 	}
     31 }