-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstnew.c
40 lines (37 loc) · 1.42 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: mschumac <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/30 21:50:48 by mschumac #+# #+# */
/* Updated: 2017/06/30 22:24:03 by mschumac ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *new_node;
new_node = (t_list*)malloc(sizeof(t_list));
if (new_node == NULL)
return (NULL);
if (content == NULL)
{
new_node->content = NULL;
new_node->content_size = 0;
}
else
{
new_node->content = malloc(content_size);
if (new_node->content == NULL)
{
free(new_node->content);
return (NULL);
}
ft_memcpy(new_node->content, content, content_size);
new_node->content_size = content_size;
}
new_node->next = NULL;
return (new_node);
}