-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memccpy_bonus.c
40 lines (36 loc) · 1.53 KB
/
ft_memccpy_bonus.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
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aviholai <aviholai@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/26 14:52:00 by aviholai #+# #+# */
/* Updated: 2022/02/04 15:41:41 by aviholai ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** 'Memccpy()' (memory character copy) function copies 'n' amount of bytes from
** memory area 'src' to memory area 'dst', or stops if it encounters a copy
** of 'c' in the string and returns that location in the string 'dst'.
** Otherwise, 'n' bytes are copied and a NULL pointer is returned. If 'dst'
** and 'src' overlap, behavior is undefined.
*/
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
char *dst2;
char *src2;
i = 0;
dst2 = (char *)dst;
src2 = (char *)src;
while (i < n)
{
dst2[i] = src2[i];
if ((unsigned char)src2[i] == (unsigned char)c)
return ((char *)dst + i + 1);
i++;
}
return (NULL);
}