pipex/libft/ft_strnstr.c
Etienne Rey-bethbeder 5f970ff3d8 0.1
2023-01-11 17:36:09 +01:00

38 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/28 09:37:24 by erey-bet #+# #+# */
/* Updated: 2022/10/05 16:39:12 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t y;
char *b;
b = (char *)big;
i = 0;
if (!*little || (little == big && ft_strlen(little) <= len))
return (b);
while (i < len && big[i])
{
y = 0;
while (b[i + y] == little[y] && i + y < len)
{
y++;
if (little[y] == '\0')
return (&b[i]);
}
i++;
}
return (NULL);
}