diff options
Diffstat (limited to 'usbmuxd/utils.c')
| -rw-r--r-- | usbmuxd/utils.c | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/usbmuxd/utils.c b/usbmuxd/utils.c deleted file mode 100644 index 1ffa04a..0000000 --- a/usbmuxd/utils.c +++ /dev/null | |||
| @@ -1,110 +0,0 @@ | |||
| 1 | /* | ||
| 2 | usbmuxd - iPhone/iPod Touch USB multiplex server daemon | ||
| 3 | |||
| 4 | Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com> | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation, either version 2 or version 3. | ||
| 9 | |||
| 10 | This program 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 General Public License for more details. | ||
| 14 | |||
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 18 | |||
| 19 | */ | ||
| 20 | |||
| 21 | #ifdef HAVE_CONFIG_H | ||
| 22 | #include <config.h> | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #include <stdlib.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include "utils.h" | ||
| 28 | #include "log.h" | ||
| 29 | |||
| 30 | void fdlist_create(struct fdlist *list) | ||
| 31 | { | ||
| 32 | list->count = 0; | ||
| 33 | list->capacity = 4; | ||
| 34 | list->owners = malloc(sizeof(*list->owners) * list->capacity); | ||
| 35 | list->fds = malloc(sizeof(*list->fds) * list->capacity); | ||
| 36 | } | ||
| 37 | void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events) | ||
| 38 | { | ||
| 39 | if(list->count == list->capacity) { | ||
| 40 | list->capacity *= 2; | ||
| 41 | list->owners = realloc(list->owners, sizeof(*list->owners) * list->capacity); | ||
| 42 | list->fds = realloc(list->fds, sizeof(*list->fds) * list->capacity); | ||
| 43 | } | ||
| 44 | list->owners[list->count] = owner; | ||
| 45 | list->fds[list->count].fd = fd; | ||
| 46 | list->fds[list->count].events = events; | ||
| 47 | list->fds[list->count].revents = 0; | ||
| 48 | list->count++; | ||
| 49 | } | ||
| 50 | |||
| 51 | void fdlist_free(struct fdlist *list) | ||
| 52 | { | ||
| 53 | list->count = 0; | ||
| 54 | list->capacity = 0; | ||
| 55 | free(list->owners); | ||
| 56 | list->owners = NULL; | ||
| 57 | free(list->fds); | ||
| 58 | list->fds = NULL; | ||
| 59 | } | ||
| 60 | |||
| 61 | void 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 | |||
| 68 | void collection_free(struct collection *col) | ||
| 69 | { | ||
| 70 | free(col->list); | ||
| 71 | col->list = NULL; | ||
| 72 | col->capacity = 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | void 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 | |||
| 90 | void 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 | |||
| 102 | int 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 | } | ||
