memmove_s、wmemmove_smemmove_s, wmemmove_s

将一个缓冲区移到另一个缓冲区。Moves one buffer to another. CRT 中的安全功能中所述,这些版本的 memmove、wmemmove 具有安全增强功能。These are versions of memmove, wmemmove with security enhancements as described in Security Features in the CRT.

语法Syntax

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
);

参数Parameters

destdest
目标对象。Destination object.

numberOfElementsnumberOfElements
目标缓冲区的大小。Size of the destination buffer.

srcsrc
源对象。Source object.

countcount
字节数 (memmove_s) 或字符 (wmemmove_s) 来复制。Number of bytes (memmove_s) or characters (wmemmove_s) to copy.

返回值Return Value

如果成功,则为零;如果失败,则为错误代码Zero if successful; an error code on failure

错误条件Error Conditions

destdest numberOfElementsnumberOfElements srcsrc 返回值Return value 内容目标Contents of dest
NULLNULL 任何any 任何any EINVALEINVAL 未修改not modified
任何any 任何any NULLNULL EINVALEINVAL 未修改not modified
任何any < 计数< count 任何any ERANGEERANGE 未修改not modified

备注Remarks

副本计数从的字符的字节srcdestCopies count bytes of characters from src to dest. 如果某些区域的源区域和目标重叠, memmove_s可确保重叠区域中的原始源字节,将覆盖之前会复制。If some regions of the source area and the destination overlap, memmove_s ensures that the original source bytes in the overlapping region are copied before being overwritten.

如果dest或如果src是 null 指针,或者如果目标字符串过小,这些函数将调用无效参数处理程序中中, 所述参数验证 .If dest or if src is a null pointer, or if the destination string is too small, these functions invoke an invalid parameter handler, as described in Parameter Validation . 如果允许执行继续,则这些函数将返回EINVAL并设置errnoEINVALIf execution is allowed to continue, these functions return EINVAL and set errno to EINVAL.

要求Requirements

例程Routine 必需的标头Required header
memmove_smemmove_s <string.h><string.h>
wmemmove_swmemmove_s <wchar.h><wchar.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// 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);
}

输出Output

Before: 0123456789
After: 0012345789

请参阅See also

缓冲区操作Buffer Manipulation
_memccpy_memccpy
memcpy、wmemcpymemcpy, wmemcpy
strcpy_s、wcscpy_s、_mbscpy_sstrcpy_s, wcscpy_s, _mbscpy_s
strcpy、wcscpy、_mbscpystrcpy, wcscpy, _mbscpy
strncpy_s、_strncpy_s_l、wcsncpy_s、_wcsncpy_s_l、_mbsncpy_s、_mbsncpy_s_lstrncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l
strncpy、_strncpy_l、wcsncpy、_wcsncpy_l、_mbsncpy、_mbsncpy_lstrncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l