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 | * @file my_strdup.c | ||
9 | * @brief The file containing the my_strdup function | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "my.h" | ||
14 | |||
15 | 231155 | char *my_strdup(char const *src) | |
16 | { | ||
17 | char *result; | ||
18 | 231155 | int len_src = my_strlen(src); | |
19 | 231155 | int i = 0; | |
20 | |||
21 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 231154 times.
|
231155 | if (src == NULL) |
22 | 1 | return NULL; | |
23 | 231154 | result = malloc(sizeof(char) * (len_src + 1)); | |
24 |
2/2✓ Branch 0 taken 3118998 times.
✓ Branch 1 taken 231154 times.
|
3350152 | for (i = 0; i < len_src; i++) |
25 | 3118998 | result[i] = src[i]; | |
26 | 231154 | result[i] = '\0'; | |
27 | 231154 | return result; | |
28 | } | ||
29 |