while (dp = readdir(d)) {
while ((dp = readdir(d))) {
static int removefile(statb)	struct stat *statb;{	DIR *d;	static DIRENTRY *dp;	register char *cp;	struct stat stb;	char *optarget;	int len, failures = 0;	switch (statb->st_mode & S_IFMT) {	case S_IFREG:	case S_IFLNK:		if (unlink(target) < 0) {			if (errno == ETXTBSY) {				message(MT_REMOTE|MT_NOTICE, 					"%s: unlink failed: %s",					target, SYSERR);				return(0);			} else {				error("%s: unlink failed: %s", target, SYSERR);				return(-1);			}		}		goto removed;	case S_IFDIR:		break;	default:		error("%s: not a plain file", target);		return(-1);	}	errno = 0;	if ((d = opendir(target)) == NULL) {		error("%s: opendir failed: %s", target, SYSERR);		return(-1);	}	optarget = ptarget;	len = ptarget - target;	while (dp = readdir(d)) {		if ((D_NAMLEN(dp) == 1 && dp->d_name[0] == '.') ||		    (D_NAMLEN(dp) == 2 && dp->d_name[0] == '.' &&		     dp->d_name[1] == '.'))			continue;		if (len + 1 + (int)strlen(dp->d_name) >= MAXPATHLEN - 1) {			message(MT_REMOTE|MT_WARNING, "%s/%s: Name too long", 				target, dp->d_name);			continue;		}		ptarget = optarget;		*ptarget++ = '/';		cp = dp->d_name;;		while (*ptarget++ = *cp++)			;		ptarget--;		if (lstat(target, &stb) < 0) {			message(MT_REMOTE|MT_WARNING, "%s: lstat failed: %s", 				target, SYSERR);			continue;		}		if (removefile(&stb) < 0)			++failures;	}	(void) closedir(d);	ptarget = optarget;	*ptarget = CNULL;	if (failures)		return(-1);	if (rmdir(target) < 0) {		error("%s: rmdir failed: %s", target, SYSERR);		return(-1);	}removed:	/*	 * We use MT_NOTICE instead of MT_CHANGE because this function is	 * sometimes called by other functions that are suppose to return a	 * single ack() back to the client (rdist).  This is a kludge until	 * the Rdist protocol is re-done.  Sigh.	 */	message(MT_NOTICE|MT_REMOTE, "%s: removed", target);	return(0);}