ft_lstnew.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_lstnew.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2017/12/05 13:29:31 by bchanot #+# #+# */
  9. /* Updated: 2018/04/17 11:50:02 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. t_slist *ft_lstnew(void *content, size_t content_size)
  14. {
  15. t_slist *list;
  16. if (!(list = (t_slist *)ft_memalloc(sizeof(*list))))
  17. return (NULL);
  18. if (content && content_size)
  19. {
  20. if ((list->content = ft_memalloc(content_size)))
  21. ft_memcpy(list->content, content, content_size);
  22. else
  23. return (NULL);
  24. list->content_size = content_size;
  25. }
  26. else
  27. {
  28. list->content = NULL;
  29. list->content_size = 0;
  30. }
  31. list->next = NULL;
  32. return (list);
  33. }