コード例 #1
0
static ino_t journal_findfile( void ) {
	struct ufs1_dinode *dp1;
	struct ufs2_dinode *dp2;
	ino_t ino;
	int mode;
	void *ip;
	int i;
	if ( getino( &disk, &ip, ROOTINO, &mode ) != 0 ) {
		warn( "Failed to get root inode" );
		return ( -1 );
	}
	dp2 = ip;
	dp1 = ip;
	if ( sblock.fs_magic == FS_UFS1_MAGIC ) {
		if ( (off_t) dp1->di_size >= lblktosize( &sblock, NDADDR ) ) {
			warnx( "ROOTINO extends beyond direct blocks." );
			return ( -1 );
		}
		for ( i = 0; i < NDADDR; i++ ) {
			if ( dp1->di_db[i] == 0 ) break;
			if ( ( ino = dir_search( dp1->di_db[i], sblksize( &sblock, (off_t) dp1->di_size, i ) ) ) != 0 ) return ( ino );
		}
	} else {
		if ( (off_t) dp2->di_size >= lblktosize( &sblock, NDADDR ) ) {
			warnx( "ROOTINO extends beyond direct blocks." );
			return ( -1 );
		}
		for ( i = 0; i < NDADDR; i++ ) {
			if ( dp2->di_db[i] == 0 ) break;
			if ( ( ino = dir_search( dp2->di_db[i], sblksize( &sblock, (off_t) dp2->di_size, i ) ) ) != 0 ) return ( ino );
		}
	}
	return ( 0 );
}
コード例 #2
0
void
SearchDirTest::do_search(int maxLevel) {
    struct dir_visitor visitor;
    visitor.on_dir_enter = on_dir_enter;
    visitor.on_dir_leave = on_dir_leave;
    visitor.on_file = on_file;
    dir_search(&visitor, this, t_dir_base(), maxLevel, t_em(), t_allocrator());
}
コード例 #3
0
void scan(const char *dir)
{
  DIR *dp = opendir(dir);
  if( dp == NULL) { perror( dir); return; }
  struct dirent *de;
  while((de = readdir(dp)))
  {
  char *entry_name = de->d_name;
    if(!strcmp(".", entry_name) || !strcmp("..", entry_name))
      continue;
    if(dir_search(dir, entry_name))	//recursively scanning directories
    {
     char *next = malloc(strlen(dir) + strlen(entry_name) + 2);
      sprintf(next, "%s/%s", dir, entry_name);	////sends formatted output to a string pointed to
      scan(next);
      free(next);
    }
  }
  closedir(dp);
}
コード例 #4
0
void prepare_input(dr_metalib_builder_t builder, error_monitor_t em) {
    int i;
    for(i = 0; i < input->count; ++i) {
        const char * filename;
        size_t filename_len;

        filename = input->filename[i];
        filename_len = strlen(filename);
        if (filename[filename_len - 1] == '\\' || filename[filename_len - 1] == '/') {
            ((char *)filename)[filename_len - 1] = 0;
        }

        if (dir_exist(filename, em)) {
            dir_search(&g_input_search_visitor, builder, filename, 5, em, NULL);
        }
        else if (file_exist(input->filename[i], em)) {
            dr_metalib_builder_add_file(builder, NULL, filename);
        }
        else {
            CPE_ERROR(em, "input %s not exist!", filename);
        }
    }
}
コード例 #5
0
ファイル: crunchgen.c プロジェクト: 2trill2spill/freebsd
/*
 * run the makefile for the program to find which objects are necessary
 */
void
fillin_program(prog_t *p)
{
	char path[MAXPATHLEN];
	char line[MAXLINELEN];
	FILE *f;

	snprintf(line, MAXLINELEN, "filling in parms for %s", p->name);
	status(line);

	if (!p->ident)
		p->ident = genident(p->name);

	/* look for the source directory if one wasn't specified by a special */
	if (!p->srcdir) {
		p->srcdir = dir_search(p->name);
	}

	/* Determine the actual srcdir (maybe symlinked). */
	if (p->srcdir) {
		snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`",
		    p->srcdir);
		f = popen(line,"r");
		if (!f)
			errx(1, "Can't execute: %s\n", line);

		path[0] = '\0';
		fgets(path, sizeof path, f);
		if (pclose(f))
			errx(1, "Can't execute: %s\n", line);

		if (!*path)
			errx(1, "Can't perform pwd on: %s\n", p->srcdir);

		p->realsrcdir = strdup(path);
	}

	/* Unless the option to make object files was specified the
	* the objects will be built in the source directory unless
	* an object directory already exists.
	*/
	if (!makeobj && !p->objdir && p->srcdir) {
		char *auto_obj;

		auto_obj = NULL;
		snprintf(line, sizeof line, "%s/%s", objprefix, p->realsrcdir);
		if (is_dir(line) ||
		    ((auto_obj = getenv("MK_AUTO_OBJ")) != NULL &&
		    strcmp(auto_obj, "yes") == 0)) {
			if ((p->objdir = strdup(line)) == NULL)
			out_of_memory();
		} else
			p->objdir = p->realsrcdir;
	}

	/*
	* XXX look for a Makefile.{name} in local directory first.
	* This lets us override the original Makefile.
	*/
	snprintf(path, sizeof(path), "Makefile.%s", p->name);
	if (is_nonempty_file(path)) {
		snprintf(line, MAXLINELEN, "Using %s for %s", path, p->name);
		status(line);
	} else
		if (p->srcdir)
			snprintf(path, sizeof(path), "%s/Makefile", p->srcdir);
	if (!p->objs && p->srcdir && is_nonempty_file(path))
		fillin_program_objs(p, path);

	if (!p->srcdir && !p->objdir && verbose)
		warnx("%s: %s: %s",
		    "warning: could not find source directory",
		    infilename, p->name);
	if (!p->objs && verbose)
		warnx("%s: %s: warning: could not find any .o files",
		    infilename, p->name);

	if ((!p->srcdir || !p->objdir) && !p->objs)
		p->goterror = 1;
}
コード例 #6
0
ファイル: crunchgen.c プロジェクト: jyin0813/OpenBSD-src
void 
fillin_program(prog_t * p)
{
	char            path[MAXPATHLEN];
	char           *srcparent;
	strlst_t       *s;
	int             i;

	snprintf(line, sizeof(line), "filling in parms for %s", p->name);
	status(line);

	if (!p->ident)
		p->ident = genident(p->name);
	if (!p->srcdir) {
		srcparent = dir_search(p->name);
		if (srcparent)
			snprintf(path, sizeof(path), "%s/%s", srcparent, p->name);
		if (is_dir(path))
			p->srcdir = strdup(path);
	}
	if (!p->objdir && p->srcdir) {
		snprintf(path, sizeof(path), "%s/%s", p->srcdir, objdir);
		if (is_dir(path))
			p->objdir = strdup(path);
		else {
			snprintf(path, sizeof(path), "%s/obj.%s", p->srcdir, MACHINE);
			if (is_dir(path))
				p->objdir = strdup(path);
			else
				p->objdir = p->srcdir;
		}
	}
	/* We have a sourcedir and no explicit objs, try */
	/* to find makefile and get objs from it. */
	if (p->srcdir && !p->objs) {
		for (i = 0; mf_name[i] != NULL; i++) {
			snprintf(path, sizeof(path), "%s/%s", p->srcdir, mf_name[i]);
			if (is_nonempty_file(path)) {
				p->mf_name = mf_name[i];
				fillin_program_objs(p, path);
				break;
			}
		}
	}
	if (!p->objpaths && p->objdir && p->objs)
		for (s = p->objs; s != NULL; s = s->next) {
			snprintf(line, sizeof(line), "%s/%s", p->objdir, s->str);
			add_string(&p->objpaths, line);
		}

	if (!p->srcdir && verbose)
		fprintf(stderr, "%s: %s: warning: could not find source directory.\n",
		    infilename, p->name);
	if (!p->objs && verbose)
		fprintf(stderr, "%s: %s: warning: could not find any .o files.\n",
		    infilename, p->name);

	if (!p->objpaths) {
		fprintf(stderr,
		    "%s: %s: error: no objpaths specified or calculated.\n",
		    infilename, p->name);
		p->goterror = goterror = 1;
	}
}