-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_memccpy.c
42 lines (38 loc) · 1.58 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
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/27 13:05:26 by apuchill #+# #+# */
/* Updated: 2020/02/19 14:04:32 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: copy string until character found
**
** DESCRIPTION:
** The memccpy() function copies bytes from string s2 to string s1. If the
** character c (as converted to an unsigned char) occurs in the string s2,
** the copy stops and a pointer to the byte after the copy of c in the
** string s1 is returned. Otherwise, n bytes are copied, and a NULL pointer
** is returned.
*/
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
i = 0;
if (!dst && !src)
return (0);
while (i < n)
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
if ((unsigned char)c == ((unsigned char *)src)[i])
return (dst + i + 1);
i++;
}
return (0);
}