-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstnew.c
42 lines (38 loc) · 1.4 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
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:17:21 by mwilliam #+# #+# */
/* Updated: 2016/12/03 12:17:22 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Allocates with malloc and returns a "fresh" link
*/
t_list*ft_lstnew(void const *content, size_t content_size)
{
t_list *fresh;
if (!(fresh = (t_list *)malloc(sizeof(t_list))))
return (NULL);
if (fresh)
{
if (!content)
{
fresh->content = NULL;
fresh->content_size = 0;
}
else
{
if (!(fresh->content = malloc(content_size)))
return (NULL);
ft_memcpy(fresh->content, content, content_size);
fresh->content_size = content_size;
}
fresh->next = NULL;
}
return (fresh);
}