Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2024 | ||
3 | ** my_calloc | ||
4 | ** File description: | ||
5 | ** Free allocated memory (type 0) or allocates memory (type 1) | ||
6 | ** of a certain size (element_count * element_size) and initializes it to zero | ||
7 | */ | ||
8 | /** | ||
9 | * @file my_calloc.c | ||
10 | * @brief The file containing the my_calloc function | ||
11 | * @author Nicolas TORO | ||
12 | */ | ||
13 | |||
14 | #include "mymemory.h" | ||
15 | |||
16 | 3769 | void *my_calloc(size_t element_count, size_t element_size, int type) | |
17 | { | ||
18 | static node_t *list = NULL; | ||
19 | void *ptr; | ||
20 | |||
21 |
5/6✓ Branch 0 taken 2867 times.
✓ Branch 1 taken 902 times.
✓ Branch 2 taken 2866 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2866 times.
✗ Branch 5 not taken.
|
3769 | if (type == 1 && element_count > 0 && element_size > 0) { |
22 | 2866 | ptr = malloc(element_count * element_size); | |
23 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2865 times.
|
2866 | if (ptr == NULL) |
24 | 1 | return NULL; | |
25 | 2865 | my_push_front(&list, ptr, VOID); | |
26 | 2865 | my_memset(ptr, 0, element_count * element_size); | |
27 | 2865 | return ptr; | |
28 | } | ||
29 |
2/2✓ Branch 0 taken 902 times.
✓ Branch 1 taken 1 times.
|
903 | if (type == 0) |
30 | 902 | my_delete_list(&list); | |
31 | 903 | return NULL; | |
32 | } | ||
33 |