コード例 #1
0
ファイル: ftree.c プロジェクト: quickgold192/oslab1
int
ftree_start(void)
{
    /*
     * Set up the operation mode of fts, open the first file arg. We must
     * use FTS_NOCHDIR, as the user may have to open multiple archives and
     * if fts did a chdir off into the boondocks, we may create an archive
     * volume in a place where the user did not expect to.
     */
    ftsopts = FTS_NOCHDIR;

    /*
     * optional user flags that effect file traversal
     * -H command line symlink follow only (half follow)
     * -L follow sylinks (logical)
     * -P do not follow sylinks (physical). This is the default.
     * -X do not cross over mount points
     * -t preserve access times on files read.
     * -n select only the first member of a file tree when a match is found
     * -d do not extract subtrees rooted at a directory arg.
     */
    if (Lflag)
        ftsopts |= FTS_LOGICAL;
    else
        ftsopts |= FTS_PHYSICAL;
    if (Hflag)
#	ifdef NET2_FTS
        paxwarn(0, "The -H flag is not supported on this version");
#	else
        ftsopts |= FTS_COMFOLLOW;
#	endif
    if (Xflag)
        ftsopts |= FTS_XDEV;

    if ((fthead == NULL) && ((farray[0] = malloc(PAXPATHLEN+2)) == NULL)) {
        paxwarn(1, "Unable to allocate memory for file name buffer");
        return(-1);
    }

    if (ftree_arg() < 0)
        return(-1);
    if (tflag && (atdir_start() < 0))
        return(-1);
    return(0);
}
コード例 #2
0
ファイル: ftree.c プロジェクト: lacombar/netbsd-alc
int
ftree_start()
{

#ifndef SMALL
	/*
	 * if -M is given, the list of filenames on stdin is actually
	 * an mtree(8) specfile, so parse the specfile into a NODE *
	 * tree at ftnode, for use by next_file()
	 */
	if (Mflag) {
		if (fthead != NULL) {
			tty_warn(1,
	    "The -M flag is only supported when reading file list from stdin");
			return -1;
		}
		ftnode = spec(stdin);
		if (ftnode != NULL &&
		    (ftnode->type != F_DIR || strcmp(ftnode->name, ".") != 0)) {
			tty_warn(1,
			    "First node of specfile is not `.' directory");
			return -1;
		}
		return 0;
	}
#endif	/* SMALL */

	/*
	 * set up the operation mode of fts, open the first file arg. We must
	 * use FTS_NOCHDIR, as the user may have to open multiple archives and
	 * if fts did a chdir off into the boondocks, we may create an archive
	 * volume in an place where the user did not expect to.
	 */
	ftsopts = FTS_NOCHDIR;

	/*
	 * optional user flags that effect file traversal
	 * -H command line symlink follow only (half follow)
	 * -L follow sylinks (logical)
	 * -P do not follow sylinks (physical). This is the default.
	 * -X do not cross over mount points
	 * -t preserve access times on files read.
	 * -n select only the first member of a file tree when a match is found
	 * -d do not extract subtrees rooted at a directory arg.
	 */
	if (Lflag)
		ftsopts |= FTS_LOGICAL;
	else
		ftsopts |= FTS_PHYSICAL;
	if (Hflag)
		ftsopts |= FTS_COMFOLLOW;
	if (Xflag)
		ftsopts |= FTS_XDEV;

	if ((fthead == NULL) && ((farray[0] = malloc(PAXPATHLEN+2)) == NULL)) {
		tty_warn(1, "Unable to allocate memory for file name buffer");
		return -1;
	}

	if (ftree_arg() < 0)
		return -1;
	if (tflag && (atdir_start() < 0))
		return -1;
	return 0;
}