summaryrefslogtreecommitdiffstats
path: root/utils.c
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-04-27 01:37:05 +0200
committerGravatar Hector Martin2009-04-27 01:37:05 +0200
commitd982007a7350df35c5aeba820a520779694514a7 (patch)
tree62d16ab56c7f92b12999bbcdbe7ce0f9293fe069 /utils.c
parent677fa91e376b98d871bb238ecb84685dd4f33ebd (diff)
downloadusbmuxd-d982007a7350df35c5aeba820a520779694514a7.tar.gz
usbmuxd-d982007a7350df35c5aeba820a520779694514a7.tar.bz2
general framework, unix socket listen, utils
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..c3d5c50
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,57 @@
1/*
2 usbmuxd - iPhone/iPod Touch USB multiplex server daemon
3
4Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com>
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 2 or version 3.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, 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 "utils.h"
27
28void fdlist_create(fdlist *list)
29{
30 list->count = 0;
31 list->capacity = 4;
32 list->owners = malloc(sizeof(*list->owners) * list->capacity);
33 list->fds = malloc(sizeof(*list->fds) * list->capacity);
34}
35void fdlist_add(fdlist *list, enum fdowner owner, int fd, short events)
36{
37 if(list->count == list->capacity) {
38 list->capacity *= 2;
39 list->owners = realloc(list->owners, sizeof(*list->owners) * list->capacity);
40 list->fds = realloc(list->fds, sizeof(*list->fds) * list->capacity);
41 }
42 list->owners[list->count] = owner;
43 list->fds[list->count].fd = fd;
44 list->fds[list->count].events = events;
45 list->fds[list->count].revents = 0;
46 list->count++;
47}
48
49void fdlist_free(fdlist *list)
50{
51 list->count = 0;
52 list->capacity = 0;
53 free(list->owners);
54 list->owners = NULL;
55 free(list->fds);
56 list->fds = NULL;
57}