Condividi tramite


memmove_s, wmemmove_s

Sposta un buffer in un altro. Queste sono versioni di memmove, wmemmove con i miglioramenti della sicurezza come descritto in Funzionalità di sicurezza in 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 
);

Parametri

  • dest
    Oggetto di destinazione.

  • numberOfElements
    Dimensione del buffer di destinazione.

  • src
    Oggetto di origine.

  • count
    Numero di byte (memmove_s) o caratteri (wmemmove_s) da copiare.

Valore restituito

Zero se ha esito positivo; un codice di errore in caso di errore.

Condizioni di errore

dest

numberOfElements

src

Valore restituito

Contenuto di dest.

NULL

any

any

EINVAL

non modificato

any

any

NULL

EINVAL

non modificato

any

< count

any

ERANGE

non modificato

Note

Copia count byte di caratteri da src a dest*.* Se alcune aree dell'area di origine e di destinazione si sovrappongono, memmove_s si assicura che i byte di origine originali dell'area sovrapposta vengano copiati prima di essere sovrascritti.

Se dest o src è un puntatore null, o se la stringa di destinazione è troppo piccola, queste funzioni richiamano il gestore dei parametri non validi, come descritto in Convalida dei parametri. Se l'esecuzione può continuare, queste funzioni restituiscono EINVAL e impostano errno su EINVAL.

Requisiti

Routine

Intestazione obbligatoria

memmove_s

<string.h>

wmemmove_s

<wchar.h>

Per ulteriori informazioni sulla compatibilità, vedere Compatibilità nell'Introduzione.

Esempio

// 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

Equivalente .NET Framework

System::Buffer::BlockCopy

Vedere anche

Riferimenti

Modifica del buffer

_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