sm

sysmgr implemented in C
git clone git://git.ckyln.com/sm
Log | Files | Refs | README | LICENSE

rm.c (588B)


      1 /* Remove directories
      2  *
      3  * Function mostly taken from:
      4  * https://stackoverflow.com/a/5467788
      5  * Licensed under CC BY-SA 2.5
      6  */
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 #include <ftw.h>
     10 
     11 #define UNUSED(x) (void)(x)
     12 
     13 #include "../util.h"
     14 
     15 static int
     16 rm_files(const char *pathname, const struct stat *sbuf, int type, struct FTW *ftwb)
     17 {
     18 	UNUSED(sbuf);
     19 	UNUSED(ftwb);
     20 	UNUSED(type);
     21 
     22 	if (remove(pathname) < 0) {
     23 		perror("remove");
     24 		return -1;
     25 	}
     26 	return 0;
     27 }
     28 
     29 int
     30 rm_rf(char *path)
     31 {
     32 	if (nftw(path, rm_files, 64, FTW_DEPTH|FTW_PHYS) < 0) {
     33 		perror("nftw");
     34 		return -1;
     35 	}
     36 	return 0;
     37 }