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 | 43 | char *my_strndup(char const *src, int n) | |
16 | { | ||
17 | 43 | char *dest = malloc(sizeof(char) * (n + 1)); | |
18 | 43 | int i = 0; | |
19 | |||
20 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
|
43 | if (src == NULL) |
21 | 1 | return NULL; | |
22 |
4/4✓ Branch 0 taken 318 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 280 times.
✓ Branch 3 taken 38 times.
|
322 | while (src[i] != '\0' && i < n) { |
23 | 280 | dest[i] = src[i]; | |
24 | 280 | i++; | |
25 | } | ||
26 | 42 | dest[i] = '\0'; | |
27 | 42 | return dest; | |
28 | } | ||
29 |