-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstnew.c
40 lines (37 loc) · 1.36 KB
/
ft_lstnew.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
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hezzahir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:07:19 by hezzahir #+# #+# */
/* Updated: 2018/11/16 19:45:03 by hezzahir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *elem;
elem = (t_list *)malloc(sizeof(t_list));
if (!elem)
return (NULL);
if (!content)
{
elem->content = NULL;
elem->content_size = 0;
}
else
{
elem->content = (void *)malloc(content_size);
if (!elem->content)
{
free(elem);
return (NULL);
}
elem->content = ft_memcpy(elem->content, content, content_size);
elem->content_size = content_size;
}
elem->next = NULL;
return (elem);
}