GCC Code Coverage Report


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

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** my_pop_list
4 ** File description:
5 ** Return the last node of a linked list and remove it from the list
6 */
7
8 #include "mylist.h"
9
10 static void change_list(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 }
19
20 linked_list_t *my_pop_node(linked_list_t **begin,
21 void const *data_ref, int (*cmp) ())
22 {
23 linked_list_t *tmp = *begin;
24 linked_list_t *next = NULL;
25
26 while (tmp != NULL) {
27 next = tmp->next;
28 if ((cmp == NULL && tmp->data == data_ref)
29 || (cmp != NULL && cmp(tmp->data, data_ref) == 0)) {
30 change_list(begin, tmp);
31 return tmp;
32 }
33 tmp = next;
34 }
35 return NULL;
36 }
37