correction memcpy pour le cas ou dst et src sont nuls
This commit is contained in:
33
srcs/ft_calloc.c
Normal file
33
srcs/ft_calloc.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:28:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** exemple allocation for 5 integers with malloc then calloc :
|
||||
** a = (int *)malloc(5 * sizeof(int)); //5*4bytes = 20 bytes
|
||||
** free(a);
|
||||
** a = (int *)calloc(5, sizeof(int));
|
||||
**
|
||||
** allocate count * size byte of memory and
|
||||
** return a pointer to the allocated memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t count, size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
if (!count || !size || !(tmp = malloc(count * size)))
|
||||
return (NULL);
|
||||
ft_bzero(tmp, count * size);
|
||||
return (tmp);
|
||||
}
|
||||
Reference in New Issue
Block a user