diff options
Diffstat (limited to 'sink.c')
-rw-r--r-- | sink.c | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -38,13 +38,30 @@ void sink_clear(sink_info* sink) { sink = NULL; } -void sink_check_list(sink_info* sink) { +void sink_check(sink_info** sink) { + + if ((*sink) == NULL) + (*sink) = (sink_info*) calloc(1, sizeof(sink_input_info)); +} +/* + * check the list length and resize the list, if current position = max + */ +void sink_list_check(sink_info** sink_list, uint32_t* max, uint32_t counter) { + if (counter >= (*max)) { + (*max) *= 2; + sink_list = (sink_info**) realloc(sink_list, (*max) * sizeof(sink_info*)); + for (int i = counter; i < (*max); ++i) + sink_list[i] = NULL; + } +} + +void sink_check_input_list(sink_info* sink) { if (sink->input_counter >= sink->input_max) sink_input_list_enlarge(sink->input_list, &sink->input_max, sink->input_counter); } -sink_info** sink_list_init(int max) { +sink_info** sink_list_init(uint32_t max) { sink_info** sink_list = (sink_info**) calloc(max, sizeof(sink_info*)); @@ -54,13 +71,22 @@ sink_info** sink_list_init(int max) { return sink_list; } -void sink_list_clear(sink_info** sink_list, int* max) { +void sink_list_reset(sink_info** sink_list, uint32_t* counter) { + + for (int i = 0; i < (*counter); ++i) + sink_list[i]->input_counter = 0; + + (*counter) = 0; +} + +void sink_list_clear(sink_info** sink_list, uint32_t* max, uint32_t* counter) { for (int i = 0; i < (*max); ++i) if (sink_list[i] != NULL) sink_clear(sink_list[i]); (*max) = 0; + (*counter) = 0; free(sink_list); sink_list = NULL; |