Conform to NetBSD KNF due to possible inclusion in source tree
[eleutheria.git] / proplib / prop_expand.c
blob4594612fdc4193507a4610cc5a2c87d761feac86
1 #include <err.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <prop/proplib.h>
6 #define NUM_STRINGS 50
8 int
9 main(void)
11 prop_array_t pa;
12 prop_string_t ps;
13 int i;
15 /*
16 * Create array object with initial capacity 10
17 * Note that the array will expand on demand
18 * by the prop_array_add() with `EXPAND_STEP' step
19 * as defined in libprop/prop_array.c
21 pa = prop_array_create_with_capacity(10);
22 if (pa == NULL)
23 errx(EXIT_FAILURE, "prop_array_create_with_capacity()");
26 * Add up to `NUM_STRINGS' prop_string_t objects
27 * and watch how the array expands on demand
29 for (i = 0; i < NUM_STRINGS; i++) {
30 /* Print statistics */
31 printf("count = %u\tcapacity = %u\n",
32 prop_array_count(pa),
33 prop_array_capacity(pa));
35 /* Create prop_string_t object */
36 ps = prop_string_create_cstring_nocopy("test");
37 if (ps == NULL) {
38 prop_object_release(pa);
39 errx(EXIT_FAILURE, "prop_string_create_cstring_nocopy()");
42 /* Add object in array */
43 if (prop_array_add(pa, ps) == FALSE) {
44 prop_object_release(ps);
45 prop_object_release(pa);
46 errx(EXIT_FAILURE, "prop_array_add()");
49 prop_object_release(ps);
52 /* Release array object */
53 prop_object_release(pa);
55 return EXIT_SUCCESS;