if (namelen >= sizeof(locname)) namelen = sizeof(locname) - 1;
printlist(name, basename)	char *name;	char *basename;{	register struct afile *fp, *list, *listp;	register struct direct *dp;	struct afile single;	RST_DIR *dirp;	int entries, len, namelen;	char locname[MAXPATHLEN];	dp = pathsearch(name);	if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||	    (!vflag && dp->d_ino == WINO))		return;	if ((dirp = rst_opendir(name)) == NULL) {		entries = 1;		list = &single;		mkentry(name, dp, list);		len = strlen(basename) + 1;		if (strlen(name) - len > single.len) {			freename(single.fname);			single.fname = savename(&name[len]);			single.len = strlen(single.fname);		}	} else {		entries = 0;		while ((dp = rst_readdir(dirp)))			entries++;		rst_closedir(dirp);		list = (struct afile *)malloc(entries * sizeof(struct afile));		if (list == NULL) {			fprintf(stderr, "ls: out of memory\n");			return;		}		if ((dirp = rst_opendir(name)) == NULL)			panic("directory reopen failed\n");		fprintf(stderr, "%s:\n", name);		entries = 0;		listp = list;		namelen = snprintf(locname, sizeof(locname), "%s/", name);		while ((dp = rst_readdir(dirp))) {			if (dp == NULL)				break;			if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)				continue;			if (!vflag && (dp->d_ino == WINO ||			     strcmp(dp->d_name, ".") == 0 ||			     strcmp(dp->d_name, "..") == 0))				continue;			locname[namelen] = '\0';			if (namelen + dp->d_namlen >= MAXPATHLEN) {				fprintf(stderr, "%s%s: name exceeds %d char\n",					locname, dp->d_name, MAXPATHLEN);			} else {				(void)strncat(locname, dp->d_name,				    (int)dp->d_namlen);				mkentry(locname, dp, listp++);				entries++;			}		}		rst_closedir(dirp);		if (entries == 0) {			fprintf(stderr, "\n");			free(list);			return;		}		qsort((char *)list, entries, sizeof(struct afile), fcmp);	}	formatf(list, entries);	if (dirp != NULL) {		for (fp = listp - 1; fp >= list; fp--)			freename(fp->fname);		fprintf(stderr, "\n");		free(list);	}}