Browse Source

Add memory functions

master
Elouan MARTINET 4 years ago
parent
commit
fbdc945032
  1. 26
      ft_memalloc.c
  2. 19
      ft_memdel.c
  3. 19
      ft_strclr.c
  4. 18
      ft_strdel.c
  5. 18
      ft_strnew.c

26
ft_memalloc.c

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memalloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 15:23:43 by emartine #+# #+# */
/* Updated: 2017/11/08 15:23:45 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memalloc(size_t size)
{
char *r;
size_t i;
if (!(r = (char *)malloc(size)))
return (NULL);
i = 0;
while (i < size)
r[i] = '\0';
return (r);
}

19
ft_memdel.c

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 15:23:51 by emartine #+# #+# */
/* Updated: 2017/11/08 15:23:53 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_memdel(void **ap)
{
free(*ap);
*ap = NULL;
}

19
ft_strclr.c

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strclr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 15:24:40 by emartine #+# #+# */
/* Updated: 2017/11/08 15:24:41 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_strclr(char *s)
{
while (*s)
*(s++) = '\0';
}

18
ft_strdel.c

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 15:24:24 by emartine #+# #+# */
/* Updated: 2017/11/08 15:24:26 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_strdel(char **as)
{
ft_memdel((void **)as);
}

18
ft_strnew.c

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 15:24:11 by emartine #+# #+# */
/* Updated: 2017/11/08 15:24:13 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnew(size_t size)
{
return (ft_memalloc(size + 1));
}
Loading…
Cancel
Save