From 5431fec6726c18234c9c28b014cc6f18a0d79884 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Fri, 6 Jun 2025 14:09:32 -0500 Subject: Style touchup --- src/ll.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'src/ll.c') diff --git a/src/ll.c b/src/ll.c index b8d0d4c..908f25f 100644 --- a/src/ll.c +++ b/src/ll.c @@ -66,15 +66,12 @@ void dlinkedlist_free(void *dll) { } int dlinkedlist_size(const dlinkedlist * const ll) { - if(!ll) - RETURNWERR(EINVAL, -1); - + if(!ll) ERRRET(EINVAL, -1); return ll->size; } int dlinkedlist_handlefirstnode(dlinkedlist * const ll, void *data, dll_freecb fcb) { - if(!ll) - RETURNWERR(EINVAL, 1); + if(!ll) ERRRET(EINVAL, 1); if(ll->size > 0) return 1; @@ -92,10 +89,7 @@ int dlinkedlist_handlefirstnode(dlinkedlist * const ll, void *data, dll_freecb f } int dlinkedlist_xxxend(dlinkedlist * const ll, void *data, dll_freecb fcb, char op) { - if(!ll) - RETURNWERR(EINVAL, 1); - if(op != 'a' && op != 'p') - RETURNWERR(EINVAL, 1); + if(!ll || (op != 'a' && op != 'p')) ERRRET(EINVAL, 1); int handleret; if((handleret = dlinkedlist_handlefirstnode(ll, data, fcb)) == 0) @@ -126,6 +120,8 @@ int dlinkedlist_xxxend(dlinkedlist * const ll, void *data, dll_freecb fcb, char ll->size++; return 0; } +// TODO: Figure out where the memory leak gcc keeps complaining about is & fix it + int dlinkedlist_append(dlinkedlist * const ll, void *data, dll_freecb fcb) { return dlinkedlist_xxxend(ll, data, fcb, 'a'); @@ -136,10 +132,8 @@ int dlinkedlist_prepend(dlinkedlist * const ll, void *data, dll_freecb fcb) { } dllnode * dlinkedlist_getnode(const dlinkedlist * const ll, int index) { - if(!ll) - RETURNWERR(EINVAL, NULL); - if(index < 0 || index >= ll->size) - RETURNWERR(EINVAL, NULL); + if(!ll) ERRRET(EINVAL, NULL); + if(index < 0 || index >= ll->size) ERRRET(EINVAL, NULL); if(index == 0) return ll->start; @@ -157,10 +151,8 @@ dllnode * dlinkedlist_getnode(const dlinkedlist * const ll, int index) { } int dlinkedlist_insert(dlinkedlist * const ll, void *data, dll_freecb fcb, int index) { - if(!ll) - RETURNWERR(EINVAL, 1); - if(index < 0 || index >= ll->size) - RETURNWERR(EINVAL, 1); + if(!ll) ERRRET(EINVAL, 1); + if(index < 0 || index >= ll->size) ERRRET(EINVAL, 1); // Handle the special cases of appending or prepending if(index == 0) @@ -188,10 +180,8 @@ int dlinkedlist_insert(dlinkedlist * const ll, void *data, dll_freecb fcb, int i } int dlinkedlist_remove(dlinkedlist * const ll, int index) { - if(!ll) - RETURNWERR(EINVAL, 1); - if(index < 0 || index >= ll->size) - RETURNWERR(EINVAL, 2); + if(!ll) ERRRET(EINVAL, 1); + if(index < 0 || index >= ll->size) ERRRET(EINVAL, 2); dllnode *current = dlinkedlist_getnode(ll, index); if(!current) @@ -226,10 +216,7 @@ void* dlinkedlist_get(const dlinkedlist * const ll, int index) { } int dlinkedlist_foreach(dlinkedlist *ll, int (*callback)(void*)) { - if(!ll) - RETURNWERR(EINVAL, -1); - if(!callback) - RETURNWERR(EINVAL, -1); + if(!ll || callback == NULL) ERRRET(EINVAL, -1); for(dllnode *p = ll->start; p != NULL; p = p->next) callback(p->data); @@ -238,10 +225,8 @@ int dlinkedlist_foreach(dlinkedlist *ll, int (*callback)(void*)) { } void * dlinkedlist_poplast(dlinkedlist *ll) { - if(!ll) - RETURNWERR(EINVAL, NULL); - if(dlinkedlist_isempty(ll)) - RETURNWERR(ENODATA, NULL); + if(!ll) ERRRET(EINVAL, NULL); + if(dlinkedlist_isempty(ll)) ERRRET(ENODATA, NULL); void *data = dlinkedlist_get(ll, ll->size - 1); dlinkedlist_remove(ll, ll->size - 1); -- cgit v1.2.3