示例#1
0
bool get_all_files(char *dir_path, list_t *list) {
    check(dir_path != NULL,
          "dir_path is NULL.");
    check(list != NULL,
          "list is NULL.");
    check(is_file_or_dir(dir_path) == 2,
          "dir_path '%s' is not a directory.",
          dir_path);
    DIR *dir;
    struct dirent *ent;
    check((dir = opendir(dir_path)) != NULL,
          "could not open directory: %s", dir_path);
    while((ent = readdir(dir)) != NULL) {
        char fullpath[256];
        sprintf(fullpath, "%s/%s", dir_path, ent->d_name);
        if(ent->d_type == DT_REG) {
            check(dl_insert(list, fullpath) == 1,
                  "failed to insert %s into the list",
                  fullpath);
        } else if (ent->d_type == DT_DIR
                   && strcmp(ent->d_name, ".") != 0
                   && strcmp(ent->d_name, "..") != 0) {
            get_all_files(fullpath, list);
        }
    }
    closedir(dir);
    return 1;
error:
    if(dir != NULL) {
        closedir(dir);
    }
    return 0;
}
示例#2
0
文件: gc.c 项目: 9thScientist/SO
void fill_vec(char *dir, char *aux, int aux_size, vec_str_t* vec) {
	char* tmp;

	get_all_files(dir, aux, aux_size);

	strtok(aux, "\n");
	while((tmp = strtok(NULL, "\n"))) {
		vec_push(vec, tmp);
	}

}
示例#3
0
/* allow optimization of install case */
static int get_required_files(struct manifest *official_manifest, struct list *subs)
{
	if (cmdline_option_install) {
		return get_all_files(official_manifest, subs);
	}

	if (cmdline_option_fix) {
		return get_missing_files(official_manifest);
	}

	return 0;
}
示例#4
0
bool get_words_from_files(list_t *wordlist, char *input) {
    list_t *filelist = NULL;
    filelist = dl_init();
    check(get_all_files(input, filelist) == 1,
          "Could not compile full list.");
    int file_count = dl_count(filelist);
    int i = 0;
    char *filename = NULL;
    for(i = 0; i < file_count; i++) {
        filename = dl_get_back(filelist);
        check(filename != NULL,
              "filename was NULL.");
        read_file_word_by_word(filename, wordlist);
        check(dl_pop_back(filelist) == 1,
              "Did not pop back properly.");
    }
    dl_clear_destroy(filelist);
    return 1;
error:
    if(filelist != NULL) {
        dl_clear_destroy(filelist);
    }
    return 0;
}