Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_malloc_strdup | ||
4 | ** File description: | ||
5 | ** Returns a duplication of a string (src) with my_malloc | ||
6 | */ | ||
7 | /** | ||
8 | * @file my_malloc_strdup.c | ||
9 | * @brief The file containing the my_malloc_strdup function | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "mymemory.h" | ||
14 | |||
15 | 4 | char *my_malloc_strdup(char const *src) | |
16 | { | ||
17 | char *result; | ||
18 | 4 | int len_src = my_strlen(src); | |
19 | 4 | int i = 0; | |
20 | |||
21 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (src == NULL) |
22 | 1 | return NULL; | |
23 | 3 | result = my_malloc(sizeof(char) * (len_src + 1), 1); | |
24 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
|
24 | for (i = 0; i < len_src; i++) |
25 | 21 | result[i] = src[i]; | |
26 | 3 | result[i] = '\0'; | |
27 | 3 | return result; | |
28 | } | ||
29 |