| 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 | 118 | char *my_strdup(char const *src) | |
| 16 | { | ||
| 17 | char *result; | ||
| 18 | 118 | int len_src = my_strlen(src); | |
| 19 | 118 | int i = 0; | |
| 20 | |||
| 21 | 2/2✓ Branch 0 taken 1 times. ✓ Branch 1 taken 117 times. | 118 | if (src == NULL) | 
| 22 | 1 | return NULL; | |
| 23 | 117 | result = malloc(sizeof(char) * (len_src + 1)); | |
| 24 | 2/2✓ Branch 0 taken 851 times. ✓ Branch 1 taken 117 times. | 968 | for (i = 0; i < len_src; i++) | 
| 25 | 851 | result[i] = src[i]; | |
| 26 | 117 | result[i] = '\0'; | |
| 27 | 117 | return result; | |
| 28 | } | ||
| 29 |