forked from droundy/fac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listset.c
46 lines (40 loc) · 977 Bytes
/
listset.c
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
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdlib.h>
#include <string.h>
#include "listset.h"
void delete_from_listset(listset **list, const char *path) {
while (*list != NULL) {
if (strcmp((*list)->path, path) == 0) {
listset *to_be_deleted = *list;
*list = (*list)->next;
free(to_be_deleted->path);
free(to_be_deleted);
return;
}
list = &((*list)->next);
}
}
int is_in_listset(const listset *ptr, const char *path) {
while (ptr != NULL) {
if (strcmp(ptr->path, path) == 0) {
return 1;
}
ptr = ptr->next;
}
return 0;
}
void insert_to_listset(listset **list, const char *path) {
delete_from_listset(list, path);
listset *newhead = (listset *)malloc(sizeof(listset));
newhead->next = *list;
newhead->path = malloc(strlen(path)+1);
strcpy(newhead->path, path);
*list = newhead;
}
void free_listset(listset *list) {
while (list != NULL) {
listset *d = list;
list = list->next;
free(d->path);
free(d);
}
}