-
Notifications
You must be signed in to change notification settings - Fork 23
/
ft_lstdelone.c
35 lines (32 loc) · 1.86 KB
/
ft_lstdelone.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pbie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/01 17:17:21 by pbie #+# #+# */
/* Updated: 2015/12/02 18:26:23 by pbie ### ########.fr */
/* */
/* ************************************************************************** */
/*In this function we are taking in, as a parameter, the address of a pointer on
* a link and freeing the memory content of the link with the function 'del'
* that has been passed as a parameter as well in order to free the memory of
* the link. The memory of the element next should never be freed. In order to
* terminate the link, the pointer on the current link should be put to NULL.*/
#include "libft.h"
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
{
/*First we check to make sure that the parameters that were passed into our
* function are not NULL. If they are not we then run our parameter passed
* function del by giving it's parameters our link alst's content and
* content_size. Once the function has deleted alst's content we the free
* the memory that was allocated to alst and then set it to NULL. Thus
* deleting on link in our list.*/
if (del != NULL && alst != NULL)
{
del((**alst).content, (**alst).content_size);
free(*alst);
*alst = NULL;
}
}