summaryrefslogtreecommitdiff
path: root/xpp/xtalk/xlist.c
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2011-03-10 18:48:11 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2011-03-10 18:48:11 +0000
commit760d0a2a75aba6307550bf551c5eb06174c256b5 (patch)
treed526eeb7d5ce0aec9e4572f5df0cb3536a2632d1 /xpp/xtalk/xlist.c
parentcf84710ff24dd09e80f9e5ecfeb16ce15137ddc3 (diff)
xpp: use 'xtalk' for the USB access code
* Move most of the USB access code from xpp/ to xpp/xtalk/ . * astribank_tool and such tools can now use a shorter -D mmm/nnn rather than a full path. Signed-off-by: Oron Peled <oron.peled@xorcom.com> Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com> git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@9825 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/xtalk/xlist.c')
-rw-r--r--xpp/xtalk/xlist.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/xpp/xtalk/xlist.c b/xpp/xtalk/xlist.c
new file mode 100644
index 0000000..d28debd
--- /dev/null
+++ b/xpp/xtalk/xlist.c
@@ -0,0 +1,93 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xlist.h>
+
+struct xlist_node *xlist_new(void *data)
+{
+ struct xlist_node *list;
+
+ if((list = malloc(sizeof(*list))) == NULL)
+ return NULL;
+ list->next = list;
+ list->prev = list;
+ list->data = data;
+ return list;
+}
+
+void xlist_destroy(struct xlist_node *list, xlist_destructor_t destructor)
+{
+ struct xlist_node *curr;
+ struct xlist_node *next;
+
+ if (! list)
+ return;
+ curr = list->next;
+ while(curr != list) {
+ next = curr->next;
+ if(destructor)
+ destructor(curr->data);
+ memset(curr, 0, sizeof(*curr));
+ free(curr);
+ curr = next;
+ }
+ memset(list, 0, sizeof(*list));
+ free(list);
+}
+
+void xlist_append_item(struct xlist_node *list, struct xlist_node *item)
+{
+ assert(list);
+ assert(xlist_empty(item));
+ item->next = list;
+ item->prev = list->prev;
+ list->prev->next = item;
+ list->prev = item;
+}
+
+void xlist_prepend_item(struct xlist_node *list, struct xlist_node *item)
+{
+ assert(list);
+ assert(xlist_empty(item));
+ item->prev = list;
+ item->next = list->next;
+ list->next->prev = item;
+ list->next = item;
+}
+
+void xlist_remove_item(struct xlist_node *item)
+{
+ assert(item);
+ item->prev->next = item->next;
+ item->next->prev = item->prev;
+ item->next = item->prev = item;
+}
+
+struct xlist_node *xlist_shift(struct xlist_node *list)
+{
+ struct xlist_node *item;
+
+ if(!list)
+ return NULL;
+ if(xlist_empty(list))
+ return NULL;
+ item = list->next;
+ xlist_remove_item(item);
+ return item;
+}
+
+int xlist_empty(const struct xlist_node *list)
+{
+ assert(list);
+ return list->next == list && list->prev == list;
+}
+
+size_t xlist_length(const struct xlist_node *list)
+{
+ struct xlist_node *curr;
+ size_t count = 0;
+
+ for(curr = list->next; curr != list; curr = curr->next)
+ count++;
+ return count;
+}