register FTSENT *freep, *p;
FTSENT *freep, *p;
fts_close(sp)	FTS *sp;{	register FTSENT *freep, *p;	int saved_errno = 0;	/*	 * This still works if we haven't read anything -- the dummy structure	 * points to the root list, so we step through to the end of the root	 * list which has a valid parent pointer.	 */	if (sp->fts_cur) {		for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {			freep = p;			p = p->fts_link ? p->fts_link : p->fts_parent;			free(freep);		}		free(p);	}	/* Free up child linked list, sort array, path buffer. */	if (sp->fts_child)		fts_lfree(sp->fts_child);	if (sp->fts_array)		free(sp->fts_array);	free(sp->fts_path);	/* Return to original directory, save errno if necessary. */	if (!ISSET(FTS_NOCHDIR)) {		saved_errno = fchdir(sp->fts_rfd) ? errno : 0;		(void)close(sp->fts_rfd);	}	/* Set errno and return. */	if (!ISSET(FTS_NOCHDIR) && saved_errno) {		/* Free up the stream pointer. */		free(sp);		errno = saved_errno;		return (-1);	}	/* Free up the stream pointer. */	free(sp);	return (0);}