/** * \brief Pushes a file name onto the stack of files. */ bool conf_includes_push(conf_includes_t *includes, const char *filename) { if (!includes || !filename) { return false; } if (!conf_includes_can_push(includes)) { return false; } char *store = NULL; if (includes->free_index == 0 || filename[0] == '/') { store = strdup(filename); } else { conf_include_t *previous = &includes->files[includes->free_index - 1]; store = path_relative_to(filename, previous->filename); } conf_include_t new_include = { .filename = store, .handle = NULL }; includes->files[includes->free_index++] = new_include; return store != NULL; }
/** * \brief Pushes a file name onto the stack of files. */ bool conf_includes_push(conf_includes_t *includes, const char *filename) { if (!includes || !filename) { return false; } char *store = NULL; if (includes->free_index == 0 || filename[0] == '/') { store = strdup(filename); } else { conf_include_t *previous = &includes->files[includes->free_index - 1]; store = path_relative_to(filename, previous->filename); } for (int i = 0; i < includes->free_index; i++) { // Check for include loop. if (strcmp(includes->files[i].filename, store) == 0) { free(store); return false; } } // Extend the stack if full. if (includes->free_index >= includes->capacity) { size_t new_size = (includes->capacity + INCLUDES_CAPACITY_BLOCK) * sizeof(conf_include_t); conf_include_t *new_files = realloc(includes->files, new_size); if (new_files == NULL) { free(store); return false; } includes->capacity = new_size; includes->files = new_files; } conf_include_t new_include = { .filename = store, .handle = NULL }; includes->files[includes->free_index++] = new_include; return store != NULL; }