register FTSENT *p;
FTSENT *p;
fts_children(sp, instr)	register FTS *sp;	int instr;{	register FTSENT *p;	int fd;	if (instr && instr != FTS_NAMEONLY) {		errno = EINVAL;		return (NULL);	}	/* Set current node pointer. */	p = sp->fts_cur;	/*	 * Errno set to 0 so user can distinguish empty directory from	 * an error.	 */	errno = 0;	/* Fatal errors stop here. */	if (ISSET(FTS_STOP))		return (NULL);	/* Return logical hierarchy of user's arguments. */	if (p->fts_info == FTS_INIT)		return (p->fts_link);	/*	 * If not a directory being visited in pre-order, stop here.  Could	 * allow FTS_DNR, assuming the user has fixed the problem, but the	 * same effect is available with FTS_AGAIN.	 */	if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)		return (NULL);	/* Free up any previous child list. */	if (sp->fts_child)		fts_lfree(sp->fts_child);	if (instr == FTS_NAMEONLY) {		SET(FTS_NAMEONLY);		instr = BNAMES;	} else		instr = BCHILD;	/*	 * If using chdir on a relative path and called BEFORE fts_read does	 * its chdir to the root of a traversal, we can lose -- we need to	 * chdir into the subdirectory, and we don't know where the current	 * directory is, so we can't get back so that the upcoming chdir by	 * fts_read will work.	 */	if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||	    ISSET(FTS_NOCHDIR))		return (sp->fts_child = fts_build(sp, instr));	if ((fd = open(".", O_RDONLY, 0)) < 0)		return (NULL);	sp->fts_child = fts_build(sp, instr);	if (fchdir(fd))		return (NULL);	(void)close(fd);	return (sp->fts_child);}