-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnlen.c
30 lines (27 loc) · 1.15 KB
/
ft_strnlen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgiraldo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 16:33:44 by mgiraldo #+# #+# */
/* Updated: 2020/02/27 10:35:00 by mgiraldo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strnlen(const char *s, size_t maxlen)
{
const char *endptr;
const char *charptr;
if (maxlen == 0)
return (0);
charptr = s - 1;
endptr = s + maxlen;
while (*++charptr)
{
if (charptr == endptr)
return (endptr - s);
}
return (charptr - s);
}