-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memccpy.c
36 lines (33 loc) · 1.32 KB
/
ft_memccpy.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
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shogura <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/06 22:26:31 by shogura #+# #+# */
/* Updated: 2022/04/06 22:31:42 by shogura ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
unsigned char *dst_cp;
unsigned char *src_cp;
unsigned char stopper;
size_t i;
i = 0;
dst_cp = (unsigned char *)dst;
src_cp = (unsigned char *)src;
stopper = (unsigned char)c;
if (dst == NULL && src == NULL)
return (NULL);
while (n-- > 0)
{
dst_cp[i] = src_cp[i];
if (dst_cp[i] == stopper)
return ((void *)dst + i + 1);
i++;
}
return (NULL);
}