memmove_s, wmemmove_s

한 버퍼를 다른 버퍼로 이동합니다. 이러한 함수는 CRTmemmovewmemmove보안 기능에 설명된 대로 보안이 향상된 버전입니다.

구문

errno_t memmove_s(
   void *dest,
   size_t numberOfElements,
   const void *src,
   size_t count
);
errno_t wmemmove_s(
   wchar_t *dest,
   size_t numberOfElements,
   const wchar_t *src,
   size_t count
);

매개 변수

dest
대상 개체입니다.

numberOfElements
대상 버퍼의 크기입니다.

src
소스 개체입니다.

count
복사할 바이트(memmove_s) 또는 문자 (wmemmove_s) 수입니다.

반환 값

성공 시 0이고, 실패 시 오류 코드입니다.

오류 조건

dest numberOfElements src 반환 값 dest의 내용
NULL any any EINVAL 수정 안 됨
any any NULL EINVAL 수정 안 됨
any < count any ERANGE 수정 안 됨

설명

문자의 countsrc 바이트를 복사합니다 dest. 원본 및 대상 영역의 일부 부분이 겹치는 memmove_s 경우 덮어쓰기 전에 겹치는 지역의 원래 원본 바이트가 복사되었는지 확인합니다.

dest null 포인터이거나 대상 문자열이 너무 작은 경우 src 이러한 함수는 매개 변수 유효성 검사에 설명된 대로 잘못된 매개 변수 처리기를 호출합니다. 계속해서 실행하도록 허용된 경우, 이러한 함수는 EINVAL를 반환하고 errnoEINVAL로 설정합니다.

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

요구 사항

루틴에서 반환된 값 필수 헤더
memmove_s <string.h>
wmemmove_s <wchar.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

// crt_memmove_s.c
//
// The program demonstrates the
// memmove_s function which works as expected
// for moving overlapping regions.

#include <stdio.h>
#include <string.h>

int main()
{
   char str[] = "0123456789";

   printf("Before: %s\n", str);

   // Move six bytes from the start of the string
   // to a new position shifted by one byte. To protect against
   // buffer overrun, the secure version of memmove requires the
   // the length of the destination string to be specified.

   memmove_s((str + 1), strnlen(str + 1, 10), str, 6);

   printf_s(" After: %s\n", str);
}

출력

Before: 0123456789
After: 0012345789

참고 항목

버퍼 조작
_memccpy
memcpy, wmemcpy
strcpy_s, wcscpy_s, _mbscpy_s
strcpy, wcscpy, _mbscpy
strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l
strncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l