get_next_line/ft_memccpy.c

38 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 14:40:00 by gbrochar #+# #+# */
/* Updated: 2019/02/06 16:20:23 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
unsigned char to_find;
unsigned char *dst_byte;
const unsigned char *src_byte;
to_find = (unsigned char)c;
i = 0;
dst_byte = (unsigned char *)dst;
src_byte = (const unsigned char *)src;
while (i != n && src_byte[i] != to_find)
{
dst_byte[i] = src_byte[i];
i++;
}
if (src_byte[i] == to_find)
{
dst_byte[i] = to_find;
return ((void *)&dst_byte[i + 1]);
}
return (NULL);
}