5 #include <sys/wait.h> /* for waitpid() macros */
6 #include <prop/proplib.h>
8 #define INIT_CAPACITY 100
15 char *tokens
[MAX_TOKENS
]; /* for ``du'' output parse */
22 /* Initiate pipe stream to ``du'' */
23 fp
= popen("du", "r");
29 /* Create dictionary */
30 pd
= prop_dictionary_create_with_capacity(INIT_CAPACITY
);
33 errx(EXIT_FAILURE
, "prop_dictionary_create_with_capacity()");
36 /* Read from stream */
37 while (fgets(str
, MAX_STR
, fp
) != NULL
) {
38 /* Parse output of ``du'' command */
40 for ((p
= strtok_r(str
, "\t", &last
)); p
;
41 (p
= strtok_r(NULL
, "\t", &last
)), i
++) {
42 if (i
< MAX_TOKENS
- 1)
47 /* Trim '\n' from tokens[1] */
48 (tokens
[1])[strlen(tokens
[1]) - 1] = '\0';
51 * We use a signed prop_number_t object, so that
52 * when externalized it will be represented as decimal
53 * (unsigned numbers are externalized in base-16)
55 pn
= prop_number_create_integer(atoi(tokens
[0]));
56 prop_dictionary_set(pd
, tokens
[1], pn
);
57 prop_object_release(pn
);
60 prop_dictionary_externalize_to_file(pd
, "./data.xml");
61 prop_object_release(pd
);
63 /* Close pipe stream */