suffix_list.c

Thu, 06 Oct 2011 00:06:30 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 06 Oct 2011 00:06:30 +0200
changeset 17
5f43f733cc12
parent 11
06cbd0ec003d
permissions
-rw-r--r--

fixed suffixList realloc bug + added destroy_suffix_list_t

10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * suffix_list.c
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Created on: 15.09.2011
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 * Author: beckermi
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 */
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 #include "suffix_list.h"
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 suffix_list_t* new_suffix_list_t() {
11
06cbd0ec003d Merge with 1dd63a32ffc486b71399045cf8443ec6ac9d7bf5
Mike Becker <universe@uap-core.de>
parents: 10
diff changeset
11 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t));
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 suffixList->count = 0;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 suffixList->items = NULL;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 return suffixList;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17
17
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
18 void destroy_suffix_list_t(suffix_list_t* list) {
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
19 if (list->items != NULL) {
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
20 free(list->items);
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
21 }
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
22 free(list);
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
23 }
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
24
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 void add_suffix(suffix_list_t* list, char* item) {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 char** reallocated_list =
17
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
27 realloc(list->items, sizeof(char*) * (list->count + 1));
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 if (reallocated_list != NULL) {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 list->items = reallocated_list;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 list->items[list->count] = item;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 list->count++;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34

mercurial