-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstnew.c
40 lines (37 loc) · 1.44 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: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/29 09:57:18 by yochered #+# #+# */
/* Updated: 2018/10/29 09:57:20 by yochered ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <stdlib.h>
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *node;
void *data;
size_t size;
if (!(node = (t_list *)malloc(sizeof(t_list))))
return (NULL);
data = (void *)content;
size = content_size;
if (!content)
{
node->content = NULL;
node->content_size = 0;
}
else
{
if (!(node->content = malloc(ft_strlen((char *)content))))
return (NULL);
node->content = ft_memcpy(node->content, data, size);
node->content_size = size;
}
node->next = NULL;
return (node);
}