Example #1
0
/*
 * prop_array_internalize_from_file --
 *	Internalize an array from a file.
 */
prop_array_t
prop_array_internalize_from_file(const char *fname)
{
	struct _prop_object_internalize_mapped_file *mf;
	prop_array_t array;

	mf = _prop_object_internalize_map_file(fname);
	if (mf == NULL)
		return (NULL);
	array = prop_array_internalize(mf->poimf_xml);
	_prop_object_internalize_unmap_file(mf);

	return (array);
}
int
main(int argc, char *argv[])
{
    int ch, nflag, status, x, verbose;
    static bstg_funcs_t bfs;
    char *buf;

    verbose = nflag = 0;
    while ((ch = getopt(argc, argv, "f:nv")) != -1) {
        switch (ch) {
            case 'n':
                nflag = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            case '?':
            default:
                usage();
        }
    }
    argv += optind-1;

    if (nflag) {
        printf("%lu\n", NFUNCS);
        return 0;
    }

    if (bstg_funcs_init(&bfs, verbose, 1048576)) {
        errx(1, "cannot init bfs");
    }

    buf = BSTGNULLCHECK(malloc(65536));

    for (x = 0; x < 128; x++) {
        pid_t pid;

        pid = fork();
        if (pid == 0) {
            srand(x);

            while (*argv++) {
                struct archive *a;
                struct archive_entry *entry;

                a = archive_read_new();
                archive_read_support_format_all(a);
                archive_read_support_filter_all(a);
                if (archive_read_open_filename(a, *argv, 10240)) {
                    _exit(2);
                }
                while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
                    size_t size;

                    size = archive_entry_size(entry);
                    buf = BSTGNULLCHECK(realloc(buf, size+1024));
                    if (archive_read_data(a, buf, size) == size) {
                        prop_array_t ops;
                        prop_number_t op;
                        prop_object_iterator_t it;
                        unsigned id;

                        /* zero terminate the file from the archive */
                        strlcat(buf, "", 1);

                        ops = BSTGNULLCHECK((prop_array_internalize(buf)));
                        it = BSTGNULLCHECK(prop_array_iterator(ops));
                        while ((op = prop_object_iterator_next(it)) != NULL) {
                            id = prop_number_unsigned_integer_value(op);
                            (*bstg_fembot_funcs[id % NFUNCS]) (&bfs);
                        }
                        prop_object_iterator_release(it);
                        prop_object_release(ops);
                    }
                }
                archive_read_close(a);
                archive_read_free(a);
            }

            if (bstg_funcs_destroy(&bfs)) {
                errx(1, "cannot destroy bfs");
            }

            _exit(1);
        }
    }

    while(wait(&status) > 0);
    while(wait(&status) > 0);
    while(wait(&status) > 0);

    if (bstg_funcs_destroy(&bfs)) {
        errx(1, "cannot destroy bfs");
    }

    return 0;
}
Example #3
0
File: main.c Project: xdave/xbps
"</array>\n"
"</plist>\n";

ATF_TC(array_replace_dict_by_name_test);

ATF_TC_HEAD(array_replace_dict_by_name_test, tc)
{
	atf_tc_set_md_var(tc, "descr", "Test xbps_array_replace_dict_by_name");
}

ATF_TC_BODY(array_replace_dict_by_name_test, tc)
{
	prop_array_t orig, new;
	prop_dictionary_t d;

	orig = prop_array_internalize(axml);
	ATF_REQUIRE_EQ(prop_object_type(orig), PROP_TYPE_ARRAY);

	new = prop_array_internalize(axml2);
	ATF_REQUIRE_EQ(prop_object_type(new), PROP_TYPE_ARRAY);

	d = prop_dictionary_create();
	ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
	ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "pkgname", "bfoo"), true);
	ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "pkgver", "bfoo-1.2"), true);
	ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "version", "1.2"), true);

	ATF_REQUIRE_EQ(xbps_array_replace_dict_by_name(orig, d, "afoo"), 0);
	ATF_REQUIRE_EQ(prop_array_equals(orig, new), true);
}