memmove_s, wmemmove_s
Updated: July 2009
Moves one buffer to another. These are versions of memmove, wmemmove with security enhancements as described in Security Enhancements in the CRT.
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 );
Copies count bytes of characters from src to dest. 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.
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 . If execution is allowed to continue, these functions return EINVAL and set errno to EINVAL.
|
Routine |
Required header |
|---|---|
|
memmove_s |
<string.h> |
|
wmemmove_s |
<wchar.h> |
For additional compatibility information, see Compatibility in the Introduction.
// 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);
}