GCC Code Coverage Report


Directory: ./
File: lib/my/my_strndup.c
Date: 2024-05-07 14:54:03
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 1 1 100.0%
Branches: 6 6 100.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** my_strndup
4 ** File description:
5 ** Returns a duplication of a string (src) with a defined size (n)
6 */
7 /**
8 * @file my_strndup.c
9 * @brief The file containing the my_strndup function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 87 char *my_strndup(char const *src, int n)
16 {
17 87 char *dest = malloc(sizeof(char) * (n + 1));
18 87 int i = 0;
19
20
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 86 times.
87 if (src == NULL)
21 1 return NULL;
22
4/4
✓ Branch 0 taken 1036 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 956 times.
✓ Branch 3 taken 80 times.
1042 while (src[i] != '\0' && i < n) {
23 956 dest[i] = src[i];
24 956 i++;
25 }
26 86 dest[i] = '\0';
27 86 return dest;
28 }
29