memmove

홍민주·2021년 5월 30일
0

memmove

- 함수 설명

The memmove() function copies len bytes from string src to string dst. The two strings may overlap; the copy is always done in a non-destructive manner.

- 매개변수

변수명설명
dst복사되는 메모리 주소
src복사할 메모리 주소
n복사할 길이 (byte 단위)

- 반환값

성공 : dst의 메모리 시작 주소.
실패 : NULL

- 코드

void	*memmove(void *dst, const void *src, size_t n)
{
	unsigned char	*dst_ptr;
	unsigned char	*src_ptr;
	size_t			i;

	if (n == 0 || dst == src)
		return (dst);
	i = 0;
	dst_ptr = dst;
	src_ptr = (unsigned char *)src;
	if (dst < src)
	{
		while (i++ < n)
			*dst_ptr++ = *src_ptr++;
	}
	else
	{
		while (i < n)
		{
			dst_ptr[n - i - 1] = src_ptr[n - i - 1];
			i++;
		}
	}
	return (dst);
}
profile
백엔드 주니어 개발자 입니다~

0개의 댓글