-
-/*
- * amtable_alloc -- (re)allocate enough space for some number of elements.
- *
- * input: table -- pointer to pointer to table
- * current -- pointer to current number of elements
- * elsize -- size of a table element
- * count -- desired number of elements
- * bump -- round up factor
- * init_func -- optional element initialization function
- * output: table -- possibly adjusted to point to new table area
- * current -- possibly adjusted to new number of elements
- */
-
-int
-debug_amtable_alloc(
- const char *file,
- int line,
- void ** table,
- size_t * current,
- size_t elsize,
- size_t count,
- int bump,
- void (*init_func)(void *))
-{
- void *table_new;
- size_t table_count_new;
- size_t i;
-
- if (count >= *current) {
- table_count_new = ((count + bump) / bump) * bump;
- table_new = debug_alloc(file, line, table_count_new * elsize);
- if (0 != *table) {
- memcpy(table_new, *table, *current * elsize);
- free(*table);
- }
- *table = table_new;
- memset(((char *)*table) + *current * elsize,
- 0,
- (table_count_new - *current) * elsize);
- if (init_func != NULL) {
- for (i = *current; i < table_count_new; i++) {
- (*init_func)(((char *)*table) + i * elsize);
- }
- }
- *current = table_count_new;
- }
- return 0;
-}
-
-/*
- * amtable_free -- release a table.
- *
- * input: table -- pointer to pointer to table
- * current -- pointer to current number of elements
- * output: table -- possibly adjusted to point to new table area
- * current -- possibly adjusted to new number of elements
- */
-
-void
-amtable_free(
- void ** table,
- size_t * current)
-{
- amfree(*table);
- *current = 0;
-}