libft
ft_lstdel.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_lstdel.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/05 16:40:13 by unite #+# #+# */
10 /* Updated: 2020/07/16 03:03:19 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 #include <stdlib.h>
16 
29 void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
30 {
31  t_list *head;
32  t_list *new_head;
33 
34  if (!alst || !(*alst) || !del)
35  return ;
36  head = *alst;
37  while (head)
38  {
39  new_head = head->next;
40  del(head->content, head->content_size);
41  free(head);
42  head = new_head;
43  }
44  *alst = NULL;
45 }
s_list::content_size
size_t content_size
The size of the data stored in bytes.
Definition: libft.h:37
ft_lstdel
void ft_lstdel(t_list **alst, void(*del)(void *, size_t))
Deletes all links in a list.
Definition: ft_lstdel.c:29
s_list
A link in a multi-purpose linked list.
Definition: libft.h:34
s_list::content
void * content
The data contained in the link.
Definition: libft.h:36
s_list::next
struct s_list * next
The next link’s address or NULL if it’s the last link.
Definition: libft.h:38
libft.h