This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memccpy.c
executable file
·41 lines (38 loc) · 1.6 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_memccpy.c :+: :+: */
/* +:+ */
/* By: fbes <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/10/26 16:31:33 by fbes #+# #+# */
/* Updated: 2022/02/08 19:48:05 by fbes ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stddef.h>
/**
* Copy a precise amount of bytes from one pointer to the other, or until
* the character c is come across. Source and destination should not overlap.
* @param[in] *dest The destination of the copy
* @param[in] *src The source to copy from
* @param[in] c The character at which to stop copying
* @param[in] n The maximum amount of bytes to copy
* @return A pointer to destination, or NULL if n == 0
*/
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
char *dest_cpy;
const char *src_cpy;
dest_cpy = dest;
src_cpy = src;
while (n > 0)
{
*dest_cpy = *src_cpy;
dest_cpy++;
if (*src_cpy == (unsigned char)c)
return ((void *)dest_cpy);
src_cpy++;
n--;
}
return (NULL);
}