summaryrefslogtreecommitdiffstats
path: root/utils.c
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-04-30 05:52:10 +0200
committerGravatar Hector Martin2009-04-30 05:52:10 +0200
commit49a8ef4fcbc8e76ca0f484e6b2d2d9eea70596b6 (patch)
treed42281bbc3b17af0f92daa5d35429f46bdd2130f /utils.c
parent53fb582e7729d5b7ed40ff04d912fcf5add7ce1c (diff)
downloadusbmuxd-49a8ef4fcbc8e76ca0f484e6b2d2d9eea70596b6.tar.gz
usbmuxd-49a8ef4fcbc8e76ca0f484e6b2d2d9eea70596b6.tar.bz2
too much stuff and it WORKS
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 41c3bcb..1ffa04a 100644
--- a/utils.c
+++ b/utils.c
@@ -23,7 +23,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23#endif 23#endif
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26#include <string.h>
26#include "utils.h" 27#include "utils.h"
28#include "log.h"
27 29
28void fdlist_create(struct fdlist *list) 30void fdlist_create(struct fdlist *list)
29{ 31{
@@ -55,3 +57,54 @@ void fdlist_free(struct fdlist *list)
55 free(list->fds); 57 free(list->fds);
56 list->fds = NULL; 58 list->fds = NULL;
57} 59}
60
61void collection_init(struct collection *col)
62{
63 col->list = malloc(sizeof(void *));
64 memset(col->list, 0, sizeof(void *));
65 col->capacity = 1;
66}
67
68void collection_free(struct collection *col)
69{
70 free(col->list);
71 col->list = NULL;
72 col->capacity = 0;
73}
74
75void collection_add(struct collection *col, void *element)
76{
77 int i;
78 for(i=0; i<col->capacity; i++) {
79 if(!col->list[i]) {
80 col->list[i] = element;
81 return;
82 }
83 }
84 col->list = realloc(col->list, sizeof(void*) * col->capacity * 2);
85 memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity);
86 col->list[col->capacity] = element;
87 col->capacity *= 2;
88}
89
90void collection_remove(struct collection *col, void *element)
91{
92 int i;
93 for(i=0; i<col->capacity; i++) {
94 if(col->list[i] == element) {
95 col->list[i] = NULL;
96 return;
97 }
98 }
99 usbmuxd_log(LL_ERROR, "collection_remove: element %p not present in collection %p (cap %d)", element, col, col->capacity);
100}
101
102int collection_count(struct collection *col)
103{
104 int i, cnt = 0;
105 for(i=0; i<col->capacity; i++) {
106 if(col->list[i])
107 cnt++;
108 }
109 return cnt;
110}