diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-05-25 13:15:13 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-05-25 13:15:13 +0200 |
commit | 21369ab14763faec0abeb4e669cb0db62121b6fd (patch) | |
tree | af413575072c79a0d0fcdd0af29c2fcab8f2f1bc /src | |
parent | 19f8170507c20d954df8002c052672d43397483d (diff) | |
download | dns-21369ab14763faec0abeb4e669cb0db62121b6fd.tar.gz |
add list for zonefile parsing (untested)
Diffstat (limited to 'src')
-rw-r--r-- | src/list.c | 50 | ||||
-rw-r--r-- | src/list.h | 25 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/list.c b/src/list.c new file mode 100644 index 0000000..6a0085f --- /dev/null +++ b/src/list.c @@ -0,0 +1,50 @@ +/* + * src/list.c + * (c) 2021 Jonas Gunz <himself@jonasgunz.de> + * License: MIT + */ + +#include "list.h" + +int list_add( list_element_t** _root, void* _data ) { + list_element_t** iter = _root; + list_element_t* new_element = malloc( sizeof(list_element_t) ); + + new_element->data = _data; + new_element->next = NULL; + + if( !new_element ) + return 1; + + while(*iter) + iter = & (*iter)->next; + + *iter = new_element; + + return 0; +} + +int list_sort ( list_element_t** _root ) { + return -1; +} + +int list_length ( list_element_t* _root ) { + return -1; +} + +void* list_pop_front ( list_element_t** _root ) { + list_element_t* old = NULL; + void* old_data = NULL; + + if( !*_root ) + return NULL; + + old = *_root; + old_data = old->data; + + *_root = (*_root)->next; + + free ( old ); + + return old_data; +} diff --git a/src/list.h b/src/list.h new file mode 100644 index 0000000..71594ad --- /dev/null +++ b/src/list.h @@ -0,0 +1,25 @@ +/* + * src/list.h + * (c) 2021 Jonas Gunz <himself@jonasgunz.de> + * License: MIT + */ + +#pragma once + +#include <stdio.h> +#include <stdlib.h> + +typedef struct list_element list_element_t; + +struct list_element { + void* data; + list_element_t* next; +}; + +int list_add( list_element_t** _root, void* _data ); + +int list_sort ( list_element_t** _root ); + +int list_length ( list_element_t* _root ); + +void* list_pop_front ( list_element_t** _root ); |