ft_lstnew

This commit is contained in:
tanguy mazé
2018-04-08 00:53:36 +02:00
parent 6c4623bde7
commit d86822d8bb
3 changed files with 66 additions and 5 deletions

38
ft_lstnew.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 00:35:42 by tmaze #+# #+# */
/* Updated: 2018/04/08 00:50:46 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *ret;
if ((ret = (t_list*)malloc(sizeof(t_list))) == NULL)
{
if (!content)
{
ret->content = NULL;
ret->content_size = 0;
}
else
{
if ((ret->content = malloc(content_size)) == NULL)
{
free(ret);
return (0);
}
ret->content_size = content_size;
}
ret->next = NULL;
}
return (ret);
}