#include #include char errbuf[ERRMAX]; int ignerr = 0; void err(char *f) { if(!ignerr){ errbuf[0] = '\0'; errstr(errbuf, sizeof errbuf); fprint(2, "rm: %s: %s\n", f, errbuf); } } /* * f is a non-empty directory. Remove its contents and then it. */ void rmdir(char *f) { char *name; int fd, i, j, n, ndir, nname; Dir *dirbuf; fd = open(f, OREAD); if(fd < 0){ err(f); return; } n = dirreadall(fd, &dirbuf); close(fd); if(n < 0){ err("dirreadall"); return; } nname = strlen(f)+1+STATMAX+1; /* plenty! */ name = malloc(nname); if(name == 0){ err("memory allocation"); return; } ndir = 0; for(i=0; iqid.type&QTDIR)) rmdir(f); else err(f); free(db); } exits(errbuf); }