work on type inference some more
[ccc.git] / util.c
diff --git a/util.c b/util.c
index a3d8bcf..fa60ddc 100644 (file)
--- a/util.c
+++ b/util.c
@@ -6,51 +6,6 @@
 
 #include "util.h"
 
-struct list *list_cons(void *el, struct list *tail)
-{
-       struct list *res = safe_malloc(sizeof(struct list));
-       res->el = el;
-       res->tail = tail;
-       return res;
-}
-
-void list_free(struct list *head, void (*freefun)(void *))
-{
-       while (head != NULL) {
-               freefun(head->el);
-               head = head->tail;
-       }
-}
-
-void **list_to_array(struct list *list, int *num, bool reverse)
-{
-       int i = list_length(list);
-       *num = i;
-       void **ptr = safe_malloc(i*sizeof(void *));
-
-       struct list *r = list;
-       while(i > 0) {
-               if (reverse)
-                       ptr[--i] = r->el;
-               else
-                       ptr[*num-(--i)] = r->el;
-               struct list *t = r;
-               r = r->tail;
-               free(t);
-       }
-       return ptr;
-}
-
-int list_length(struct list *r)
-{
-       int i = 0;
-       while(r != NULL) {
-               i++;
-               r = r->tail;
-       }
-       return i;
-}
-
 int fromHex(char c)
 {
        if (c >= '0' && c <= '9')
@@ -199,9 +154,11 @@ void *safe_malloc(size_t size)
 
 void *safe_strdup(const char *c)
 {
-       char *res = strdup(c);
+       size_t nchar = strlen(c);
+       char *res = malloc((nchar+1)*sizeof(char));
        if (res == NULL)
                pdie("strdup");
+       memcpy(res, c, nchar+1);
        return res;
 }