cf->cf_ddat = cdp;
cvs_file_getdir(CVSFILE *cf, int flags){	int ret, fd;	u_int ndirs;	long base;	void *dp, *ep;	char fbuf[2048], pbuf[MAXPATHLEN];	struct dirent *ent;	CVSFILE *cfp;	struct stat st;	struct cvs_dir *cdp;	struct cvs_flist dirs;	ndirs = 0;	TAILQ_INIT(&dirs);	cdp = cf->cf_ddat;	cdp->cd_root = cvsroot_get(cf->cf_path);	if (cdp->cd_root == NULL) {		cvs_file_freedir(cdp);		return (-1);	}	if (flags & CF_MKADMIN)		cvs_mkadmin(cf, 0755);	/* if the CVS administrative directory exists, load the info */	snprintf(pbuf, sizeof(pbuf), "%s/" CVS_PATH_CVSDIR, cf->cf_path);	if ((stat(pbuf, &st) == 0) && S_ISDIR(st.st_mode)) {		if (cvs_readrepo(cf->cf_path, pbuf, sizeof(pbuf)) == 0) {			cdp->cd_repo = strdup(pbuf);			if (cdp->cd_repo == NULL) {				free(cdp);				return (-1);			}		}		cdp->cd_ent = cvs_ent_open(cf->cf_path, O_RDWR);	}	fd = open(cf->cf_path, O_RDONLY);	if (fd == -1) {		cvs_log(LP_ERRNO, "failed to open `%s'", cf->cf_path);		cvs_file_freedir(cdp);		return (-1);	}	do {		ret = getdirentries(fd, fbuf, sizeof(fbuf), &base);		if (ret == -1) {			cvs_log(LP_ERRNO, "failed to get directory entries");			(void)close(fd);			cvs_file_freedir(cdp);			return (-1);		}		dp = fbuf;		ep = fbuf + (size_t)ret;		while (dp < ep) {			ent = (struct dirent *)dp;			dp += ent->d_reclen;			if ((flags & CF_IGNORE) && cvs_file_chkign(ent->d_name))				continue;			if ((flags & CF_NOSYMS) && (ent->d_type == DT_LNK))				continue;			snprintf(pbuf, sizeof(pbuf), "%s/%s",			    cf->cf_path, ent->d_name);			cfp = cvs_file_lget(pbuf, flags, cf);			if (cfp != NULL) {				if (cfp->cf_type == DT_DIR) { 					TAILQ_INSERT_HEAD(&dirs, cfp, cf_list);					ndirs++;				}				else {					TAILQ_INSERT_HEAD(&(cdp->cd_files), cfp,					    cf_list);					cdp->cd_nfiles++;				}			}		}	} while (ret > 0);	if (flags & CF_SORT) {		cvs_file_sort(&(cdp->cd_files), cdp->cd_nfiles);		cvs_file_sort(&dirs, ndirs);	}	TAILQ_FOREACH(cfp, &dirs, cf_list)		TAILQ_INSERT_TAIL(&(cdp->cd_files), cfp, cf_list);	cdp->cd_nfiles += ndirs;	(void)close(fd);	cf->cf_ddat = cdp;	return (0);}