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