-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_calloc.c
40 lines (36 loc) · 804 Bytes
/
_calloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "main.h"
/**
* _memset - fills memory with a constant byte.
* @s: address begin to fill the memory
* @b: value to set on memory
* @n: numbers of bytes to pointed by s
* Return: char, if executed properly
*/
char *_memset(char *s, char b, unsigned int n)
{
unsigned int cont = 0;
while (cont < n)
{
*(s + cont) = b;
cont++;
}
return (s);
}
/**
* _calloc - function that allocates memory for an array, using malloc function
* @nmemb: amount to values to store on memory
* @size: number of bytes of datatype
*
* Return: Void pointer, if executed properly
*/
void *_calloc(unsigned int nmemb, int size)
{
void *p = NULL;
if (nmemb == 0 || size == 0)
return (NULL);
p = malloc(nmemb * size);
if (p == NULL)
return (NULL);
_memset(p, 0, size * nmemb);
return (p);
}