some routines for removing a device on demand. thist do not work properly
[ppcskel.git] / usb / lib / list.c
index efb623cac7d091a0f293aac82981b48beffab6e4..9ea2090c5a0254eb6b430198380ff14d47cabcfb 100644 (file)
 //#include <stdlib.h>
 #include "list.h"
 #include "../../malloc.h"
+#include "../../string.h"
+#include "../../bootmii_ppc.h"
 
-list* list_create()
+struct list* list_create()
 {
-       list *l = (list*)malloc(sizeof(list));
+       struct list *l = (struct list*)malloc(sizeof(struct list));
        l->head = NULL;
        return l;
 }
 
-u8 list_add_tail(list *l, element *e)
+u8 list_add_tail(struct list *l, struct element *e)
 {
        e->next = NULL;
 
@@ -53,8 +55,7 @@ u8 list_add_tail(list *l, element *e)
        }
 
        /* find last element */
-       element * iterator;
-       iterator = l->head;
+       struct element *iterator = l->head;
 
        while(iterator->next!=NULL) {
                iterator = iterator->next;
@@ -66,14 +67,41 @@ u8 list_add_tail(list *l, element *e)
 
 
 
-// FIXME: untested and unused!! 
-u8 list_delete_element(list *l, element *e)
+// FIXME: untested
+u8 list_delete_element(struct list *l, struct element *e)
 {
+       struct element *iterator = l->head;
+       struct element *delete = NULL;
+
+       if(!l->head) {
+               return 0;
+       } else {
+               if(l->head->data && !(memcmp(l->head->data, e->data, sizeof(struct element)))) {
+                       delete = l->head;
+                       l->head = NULL;
+               }
+       }
+
+       while(iterator->next!=NULL) {
+               if(iterator->next->data && !(memcmp(iterator->next->data, e->data, sizeof(struct element)))) {
+                       delete = iterator->next;
+                       iterator->next = iterator->next->next;
+                       break;
+               }
+
+               iterator = iterator->next;
+       } 
+
+       if(delete) {
+               free(delete->data);
+               free(delete);
+       }
+       
        return 1;
 }
 
 // FIXME: untested and unused!! 
-u8 list_is_element_last(list *l, element *e)
+u8 list_is_element_last(struct list *l, struct element *e)
 {
        if(e->next==NULL)
                return 1;
@@ -84,10 +112,9 @@ u8 list_is_element_last(list *l, element *e)
 
 
 // FIXME: untested and unused!! 
-element * list_find_next_element(list *l, element *e)
+struct element *list_find_next_element(struct list *l, struct element *e)
 {
-       element * iterator;
-       iterator = l->head;
+       struct element *iterator = l->head;
 
        while(iterator!=NULL){
                if(iterator == e)