diff options
| author | 2013-09-17 11:30:01 +0200 | |
|---|---|---|
| committer | 2013-09-17 11:30:01 +0200 | |
| commit | f4758e8b15cd30fe3f7f18de42e2ea20bc5696f0 (patch) | |
| tree | 671e85e639b689b0b888a0f51c7dd5e15d408930 /common/utils.c | |
| parent | 10939f3ad5755d1117f20df2b97c0cbbd83bbcbe (diff) | |
| download | usbmuxd-f4758e8b15cd30fe3f7f18de42e2ea20bc5696f0.tar.gz usbmuxd-f4758e8b15cd30fe3f7f18de42e2ea20bc5696f0.tar.bz2 | |
remove libusbmuxd sources and adapt source tree to use autotools
libusbmuxd has been split off and is now managed in a separate repository.
By the time of this commit, the repository is:
git clone http://git.sukimashita.com/libusbmuxd.git
Diffstat (limited to 'common/utils.c')
| -rw-r--r-- | common/utils.c | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/common/utils.c b/common/utils.c deleted file mode 100644 index 0096907..0000000 --- a/common/utils.c +++ /dev/null | |||
| @@ -1,126 +0,0 @@ | |||
| 1 | /* | ||
| 2 | usbmuxd - iPhone/iPod Touch USB multiplex server daemon | ||
| 3 | |||
| 4 | Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com> | ||
| 5 | Copyright (C) 2009 Nikias Bassen <nikias@gmx.li> | ||
| 6 | |||
| 7 | This library is free software; you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU Lesser General Public License as | ||
| 9 | published by the Free Software Foundation, either version 2.1 of the | ||
| 10 | License, or (at your option) any later version. | ||
| 11 | |||
| 12 | This library is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU Lesser General Public | ||
| 18 | License along with this program; if not, write to the Free Software | ||
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | |||
| 21 | */ | ||
| 22 | |||
| 23 | #ifdef HAVE_CONFIG_H | ||
| 24 | #include <config.h> | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #include <stdlib.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <stdio.h> | ||
| 30 | #include "utils.h" | ||
| 31 | |||
| 32 | #ifdef USBMUXD_DAEMON | ||
| 33 | # include "log.h" | ||
| 34 | # define util_error(...) usbmuxd_log(LL_ERROR, __VA_ARGS__) | ||
| 35 | #else | ||
| 36 | # define util_error(...) fprintf(stderr, __VA_ARGS__) | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifdef USBMUXD_DAEMON | ||
| 40 | void fdlist_create(struct fdlist *list) | ||
| 41 | { | ||
| 42 | list->count = 0; | ||
| 43 | list->capacity = 4; | ||
| 44 | list->owners = malloc(sizeof(*list->owners) * list->capacity); | ||
| 45 | list->fds = malloc(sizeof(*list->fds) * list->capacity); | ||
| 46 | } | ||
| 47 | void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events) | ||
| 48 | { | ||
| 49 | if(list->count == list->capacity) { | ||
| 50 | list->capacity *= 2; | ||
| 51 | list->owners = realloc(list->owners, sizeof(*list->owners) * list->capacity); | ||
| 52 | list->fds = realloc(list->fds, sizeof(*list->fds) * list->capacity); | ||
| 53 | } | ||
| 54 | list->owners[list->count] = owner; | ||
| 55 | list->fds[list->count].fd = fd; | ||
| 56 | list->fds[list->count].events = events; | ||
| 57 | list->fds[list->count].revents = 0; | ||
| 58 | list->count++; | ||
| 59 | } | ||
| 60 | |||
| 61 | void fdlist_free(struct fdlist *list) | ||
| 62 | { | ||
| 63 | list->count = 0; | ||
| 64 | list->capacity = 0; | ||
| 65 | free(list->owners); | ||
| 66 | list->owners = NULL; | ||
| 67 | free(list->fds); | ||
| 68 | list->fds = NULL; | ||
| 69 | } | ||
| 70 | |||
| 71 | void fdlist_reset(struct fdlist *list) | ||
| 72 | { | ||
| 73 | list->count = 0; | ||
| 74 | } | ||
| 75 | #endif | ||
| 76 | |||
| 77 | void collection_init(struct collection *col) | ||
| 78 | { | ||
| 79 | col->list = malloc(sizeof(void *)); | ||
| 80 | memset(col->list, 0, sizeof(void *)); | ||
| 81 | col->capacity = 1; | ||
| 82 | } | ||
| 83 | |||
| 84 | void collection_free(struct collection *col) | ||
| 85 | { | ||
| 86 | free(col->list); | ||
| 87 | col->list = NULL; | ||
| 88 | col->capacity = 0; | ||
| 89 | } | ||
| 90 | |||
| 91 | void collection_add(struct collection *col, void *element) | ||
| 92 | { | ||
| 93 | int i; | ||
| 94 | for(i=0; i<col->capacity; i++) { | ||
| 95 | if(!col->list[i]) { | ||
| 96 | col->list[i] = element; | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | col->list = realloc(col->list, sizeof(void*) * col->capacity * 2); | ||
| 101 | memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity); | ||
| 102 | col->list[col->capacity] = element; | ||
| 103 | col->capacity *= 2; | ||
| 104 | } | ||
| 105 | |||
| 106 | void collection_remove(struct collection *col, void *element) | ||
| 107 | { | ||
| 108 | int i; | ||
| 109 | for(i=0; i<col->capacity; i++) { | ||
| 110 | if(col->list[i] == element) { | ||
| 111 | col->list[i] = NULL; | ||
| 112 | return; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | util_error("collection_remove: element %p not present in collection %p (cap %d)", element, col, col->capacity); | ||
| 116 | } | ||
| 117 | |||
| 118 | int collection_count(struct collection *col) | ||
| 119 | { | ||
| 120 | int i, cnt = 0; | ||
| 121 | for(i=0; i<col->capacity; i++) { | ||
| 122 | if(col->list[i]) | ||
| 123 | cnt++; | ||
| 124 | } | ||
| 125 | return cnt; | ||
| 126 | } | ||
