8 struct list
*list_cons(void *el
, struct list
*tail
)
10 struct list
*res
= safe_malloc(sizeof(struct list
));
16 void list_free(struct list
*head
, void (*freefun
)(void *))
18 while (head
!= NULL
) {
24 void **list_to_array(struct list
*list
, int *num
, bool reverse
)
26 int i
= list_length(list
);
28 void **ptr
= safe_malloc(i
*sizeof(void *));
30 struct list
*r
= list
;
35 ptr
[*num
-(--i
)] = r
->el
;
43 int list_length(struct list
*r
)
53 void pdie(const char *msg
)
59 void die(const char *msg
, ...)
63 vfprintf(stderr
, msg
, ap
);
68 void pindent(int indent
, FILE *out
)
70 for (int i
= 0; i
<indent
; i
++)
71 if (fputc('\t', out
) == EOF
)
75 void safe_fprintf(FILE *out
, const char *msg
, ...)
79 int r
= vfprintf(out
, msg
, ap
);
85 void *safe_malloc(size_t size
)
87 void *res
= malloc(size
);
93 void *safe_strdup(const char *c
)
95 char *res
= strdup(c
);