Changeset 2345 for lm-sensors/trunk/lib/general.c
- Timestamp:
- 03/08/04 05:39:50 (9 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/lib/general.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/lib/general.c
r207 r2345 28 28 #define A_BUNCH 16 29 29 30 void sensors_malloc_array(void * *list, int *num_el, int *max_el, int el_size)30 void sensors_malloc_array(void *list, int *num_el, int *max_el, int el_size) 31 31 { 32 *list = malloc(el_size*A_BUNCH); 33 if (! *list) 32 void **my_list = (void **)list; 33 34 *my_list = malloc(el_size*A_BUNCH); 35 if (! *my_list) 34 36 sensors_fatal_error("sensors_malloc_array","Allocating new elements"); 35 37 *max_el = A_BUNCH; … … 37 39 } 38 40 39 void sensors_free_array(void * *list, int *num_el, int *max_el)41 void sensors_free_array(void *list, int *num_el, int *max_el) 40 42 { 41 free(*list); 42 *list = NULL; 43 void **my_list = (void **)list; 44 45 free(*my_list); 46 *my_list = NULL; 43 47 *num_el = 0; 44 48 *max_el = 0; 45 49 } 46 50 47 void sensors_add_array_el(const void *el, void * *list, int *num_el,51 void sensors_add_array_el(const void *el, void *list, int *num_el, 48 52 int *max_el, int el_size) 49 53 { 50 54 int new_max_el; 55 void **my_list = (void *)list; 51 56 if (*num_el + 1 > *max_el) { 52 57 new_max_el = *max_el + A_BUNCH; 53 * list = realloc(*list,new_max_el * el_size);54 if (! * list)58 *my_list = realloc(*my_list,new_max_el * el_size); 59 if (! *my_list) 55 60 sensors_fatal_error("sensors_add_array_el","Allocating new elements"); 56 61 *max_el = new_max_el; 57 62 } 58 memcpy(((char *) * list) + *num_el * el_size, el, el_size);63 memcpy(((char *) *my_list) + *num_el * el_size, el, el_size); 59 64 (*num_el) ++; 60 65 } 61 66 62 void sensors_add_array_els(const void *els, int nr_els, void * *list,67 void sensors_add_array_els(const void *els, int nr_els, void *list, 63 68 int *num_el, int *max_el, int el_size) 64 69 { 65 70 int new_max_el; 71 void **my_list = (void *)list; 66 72 if (*num_el + nr_els > *max_el) { 67 73 new_max_el = (*max_el + nr_els + A_BUNCH); 68 74 new_max_el -= new_max_el % A_BUNCH; 69 * list = realloc(*list,new_max_el * el_size);70 if (! * list)75 *my_list = realloc(*my_list,new_max_el * el_size); 76 if (! *my_list) 71 77 sensors_fatal_error("sensors_add_array_els","Allocating new elements"); 72 78 *max_el = new_max_el; 73 79 } 74 memcpy(((char *)* list) + *num_el * el_size, els, el_size * nr_els);80 memcpy(((char *)*my_list) + *num_el * el_size, els, el_size * nr_els); 75 81 *num_el += nr_els; 76 82 }
