1 /*
2 * Copyright (C) 2009 Neverball authors
3 *
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 */
14
15 #include <stdlib.h>
16 #include "list.h"
17
18 /*
19 * Allocate and return a list cell initialised with FIRST and REST as
20 * "data" and "next" members, respectively.
21 */
list_cons(void * first,List rest)22 List list_cons(void *first, List rest)
23 {
24 List new;
25
26 if ((new = malloc(sizeof (*new))))
27 {
28 new->data = first;
29 new->next = rest;
30 }
31
32 return new;
33 }
34
35 /*
36 * Free the list cell FIRST and return the "next" member. The "data"
37 * member is not freed.
38 */
list_rest(List first)39 List list_rest(List first)
40 {
41 List rest = first->next;
42 free(first);
43 return rest;
44 }
45