GCC Code Coverage Report


Directory: ./
File: lib/my/my_strdup.c
Date: 2024-06-05 02:24:39
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 1 1 100.0%
Branches: 4 4 100.0%

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