return pakfire_parser_expand(parser, namespace, value);
}
-static int append_to_array(char*** array, const char* s) {
- unsigned int length = 0;
-
- // Determine the length of the existing array
- if (*array) {
- for (char** element = *array; *element; element++)
- length++;
- }
-
- // Allocate space
- *array = reallocarray(*array, length + 2, sizeof(**array));
- if (!*array)
- return 1;
-
- // Copy the string to the heap
- char* p = strdup(s);
- if (!p)
- return 1;
-
- // Append p and terminate the array
- (*array)[length] = p;
- (*array)[length + 1] = NULL;
-
- return 0;
-}
-
int pakfire_parser_get_filelist(struct pakfire_parser* parser, const char* namespace,
const char* name, char*** includes, char*** excludes) {
+ const char* file = NULL;
char* p = NULL;
int r = 0;
// Nothing to do for empty lists
if (!list)
- return 0;
+ goto ERROR;
- const char* file = strtok_r(list, " \n", &p);
+ // Split the string
+ file = strtok_r(list, " \n", &p);
// Split into includes and excludes
while (file) {
+ // Excludes
if (excludes && *file == '!') {
- r = append_to_array(excludes, file + 1);
- if (r)
+ r = pakfire_strings_append(excludes, file + 1);
+ if (r < 0)
goto ERROR;
- } else {
- r = append_to_array(includes, file);
- if (r)
+
+ // Includes
+ } else if (includes) {
+ r = pakfire_strings_append(includes, file);
+ if (r < 0)
goto ERROR;
}