Export (0) Print
Expand All
and
div
eof
not
or
xor
Expand Minimize

memmove_s, wmemmove_s

Moves one buffer to another. These are versions of memmove, wmemmove with security enhancements as described in Security Features 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 
);

dest

Destination object.

numberOfElements

Size of the destination buffer.

src

Source object.

count

Number of bytes (memmove_s) or characters (wmemmove_s) to copy.

Zero if successful; an error code on failure

Error Conditions

dest

numberOfElements

src

Return value

Contents of dest

NULL

any

any

EINVAL

not modified

any

any

NULL

EINVAL

not modified

any

< count

any

ERANGE

not modified

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

Before: 0123456789
 After: 0012345789
Show:
© 2014 Microsoft