GCC Code Coverage Report


Directory: ./
File: lib/mylist/my_delete_nodes.c
Date: 2024-06-05 02:24:39
Exec Total Coverage
Lines: 0 22 0.0%
Functions: 0 2 0.0%
Branches: 0 16 0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_delete_nodes
4 ** File description:
5 ** Deletes nodes from a linked list
6 */
7
8 #include "mylist.h"
9
10 static void remove_node(linked_list_t **begin, linked_list_t *tmp)
11 {
12 if (tmp->prev != NULL)
13 tmp->prev->next = tmp->next;
14 else
15 *begin = tmp->next;
16 if (tmp->next != NULL)
17 tmp->next->prev = tmp->prev;
18 if (tmp->type != UNKNOWN)
19 FREE(tmp->data);
20 FREE(tmp);
21 }
22
23 int my_delete_nodes(linked_list_t **begin, void const *data_ref, int (*cmp) ())
24 {
25 linked_list_t *tmp = *begin;
26 linked_list_t *next = NULL;
27 int nodes_deleted = 0;
28
29 while (tmp != NULL) {
30 next = tmp->next;
31 if ((cmp == NULL && tmp->data == data_ref)
32 || (cmp != NULL && cmp(tmp->data, data_ref) == 0)) {
33 remove_node(begin, tmp);
34 nodes_deleted++;
35 }
36 tmp = next;
37 }
38 return nodes_deleted;
39 }
40