aboutsummaryrefslogtreecommitdiff
path: root/src/list.c
blob: 561b308c20f9d501041e8c8f534713bb36069430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdlib.h>
#include "list.h"

/*
 * Creates a new list.
 */
List* List_Create(void)
{
  List* list = malloc(sizeof(List));

  list->next    = NULL; /* nwxt element is empty   */
  list->current = list; /* points to itself        */
  list->first   = list; /* first element is itself */
  list->data    = NULL; /* data is empty           */
  list->size    = 0;

  return list;
}

/*
 * Adds a new element to the list.
 */
void List_Add(List* list,  /* list where to add new element */
              void* data,  /* data to add                   */
              int size_of) /* size of the data              */
{
  void* dest = malloc(size_of); /* allocates memory like data parameter */

  memcpy(dest, data, size_of);  /* copies data inside dest              */
  list->data = dest;

  list->next = malloc(sizeof(List));
  list->size ++;
}