/* * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include #include char errbuf[ERRMAX]; int ignerr = 0; int printerr = 0; void err(long e, char *f) { if(printerr){ print("%s %ulld\n", f, e); } else if(!ignerr){ errbuf[0] = '\0'; sys_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; long e; int fd, i, j, n, ndir, nname; Dir *dirbuf; fd = sys_open(f, OREAD); if(fd < 0){ err(-1, f); return; } n = dirreadall(fd, &dirbuf); sys_close(fd); if(n < 0){ err(-1, "dirreadall"); return; } nname = strlen(f)+1+STATMAX+1; /* plenty! */ name = malloc(nname); if(name == 0){ err(-1, "memory allocation"); return; } ndir = 0; for(i=0; iqid.type&QTDIR)) rmdir(f); else err(e, f); free(db); } exits(errbuf); }