memalloc - AugustinLopez/libft GitHub Wiki

Introduction

From the libft PDF subject:

Name ft_memalloc
Prototype void *ft_memalloc(size_t size);
Description Allocates (with malloc(3)) and returns a "fresh" memory area. The memory allocated is initialized to 0. If the allocations fails, the function returns NULL.
Param. #1 The size of the memory that needs to be allocated.
Return value The allocated memory area.
Libc Functions malloc(3)

Relevant wiki: bzero.

Implementation

#include <stdlib.h>
#include <string.h>
#include "libft.h"

void	*ft_memalloc(size_t size)
{
	void	*p;

	if (!(p = (void *)malloc(size)))
		return (NULL);
	ft_bzero(p, size);
	return (p);
}

Further Reading

⚠️ **GitHub.com Fallback** ⚠️