2
general.c - Part of libsensors, a Linux library for reading sensor data.
3
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU Lesser General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
31
void sensors_malloc_array(void *list, int *num_el, int *max_el, int el_size)
33
void **my_list = (void **)list;
35
*my_list = malloc(el_size*A_BUNCH);
37
sensors_fatal_error(__func__, "Allocating new elements");
42
void sensors_free_array(void *list, int *num_el, int *max_el)
44
void **my_list = (void **)list;
52
void sensors_add_array_el(const void *el, void *list, int *num_el,
53
int *max_el, int el_size)
56
void **my_list = (void *)list;
57
if (*num_el + 1 > *max_el) {
58
new_max_el = *max_el + A_BUNCH;
59
*my_list = realloc(*my_list, new_max_el * el_size);
61
sensors_fatal_error(__func__,
62
"Allocating new elements");
65
memcpy(((char *) *my_list) + *num_el * el_size, el, el_size);
69
void sensors_add_array_els(const void *els, int nr_els, void *list,
70
int *num_el, int *max_el, int el_size)
73
void **my_list = (void *)list;
74
if (*num_el + nr_els > *max_el) {
75
new_max_el = (*max_el + nr_els + A_BUNCH);
76
new_max_el -= new_max_el % A_BUNCH;
77
*my_list = realloc(*my_list, new_max_el * el_size);
79
sensors_fatal_error(__func__,
80
"Allocating new elements");
83
memcpy(((char *)*my_list) + *num_el * el_size, els, el_size * nr_els);