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