minishell
ft_memmove.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* ft_memmove.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/06 19:57:26 by kfujita #+# #+# */
9 /* Updated: 2022/04/25 23:42:13 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <string.h>
14 #include "ft_mem.h"
15 
16 void *ft_memmove(void *dst, const void *src, size_t n)
17 {
18  unsigned char *p_c_dst;
19  unsigned char *p_c_src;
20  signed char direction;
21 
22  if (src == dst || n == 0)
23  return (dst);
24  p_c_dst = (unsigned char *)dst;
25  p_c_src = (unsigned char *)src;
26  if (dst > src)
27  {
28  p_c_dst += n - 1;
29  p_c_src += n - 1;
30  direction = -1;
31  }
32  else
33  direction = 1;
34  while (n-- > 0)
35  {
36  *p_c_dst = *p_c_src;
37  p_c_dst += direction;
38  p_c_src += direction;
39  }
40  return (dst);
41 }
void * ft_memmove(void *dst, const void *src, size_t n)
Definition: ft_memmove.c:16