-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
80 lines (75 loc) · 2.35 KB
/
ft_memmove.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zakchouc <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 14:11:30 by zakchouc #+# #+# */
/* Updated: 2024/12/02 22:33:52 by zakchouc ### ########.fr */
/* */
/* ************************************************************************** */
/**
* @file ft_memmove.c
* @author Ziyad A. Dev ([email protected])
* @brief The memmove() function copies n bytes from memory area src to
* memory area dest. The memory areas may overlap: copying takes
* place as though the bytes in src are first copied into a temporary
* array that does not overlap src or dest, and the bytes are then
* copied from the temporary array to dest.
* @param dest : Destination memory area
* @param src : Memory area from which to copy
* @param n : Number of byte to move
* @return Pointer to dest.
* @version 0.1
* @date 2023-12-05
*
* @copyright Copyright (c) 2023
*
*/
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned char *src_tmp;
unsigned char *dest_tmp;
int i;
if (!dest && !src)
return (NULL);
src_tmp = (unsigned char *)src;
dest_tmp = (unsigned char *)dest;
i = 0;
if (dest > src)
{
while (n-- > 0)
dest_tmp[n] = src_tmp[n];
}
else
{
while (n-- > 0)
{
dest_tmp[i] = src_tmp[i];
i++;
}
}
return (dest);
}
// int main(void)
// {
// char data_ori[50] = "abcdef";
// char data_ft[50] = "abcdef";
//
// char dest_ft[3] = "ghi";
// char dest_ori[3] = "ghi";
//
// printf("src_ft : %s\n", data_ft);
// printf("src_ori : %s\n", data_ori);
//
// ft_memmove(dest_ft, data_ft, 3);
// memmove(dest_ori, data_ori, 3);
//
// printf("\nmemmove ----------\n");
// printf("dest_ft : %s\n", data_ft);
// printf("dest_ori : %s\n", data_ori);
//
// return(0);
// }