memmovewmemmove

バッファーを別のバッファーに移動します。 これらの関数のセキュリティを強化したバージョンを使用できます。「memmove_swmemmove_s」を参照してください。

構文

void *memmove(
   void *dest,
   const void *src,
   size_t count
);
wchar_t *wmemmove(
   wchar_t *dest,
   const wchar_t *src,
   size_t count
);

パラメーター

dest
コピー先のオブジェクト。

src
コピー元のオブジェクト。

count
コピーするバイト数 (memmove) または文字数 (wmemmove)。

戻り値

dest の値。

解説

count バイト (memmove) または文字 (wmemmove) を src から dest にコピーします。 コピー元とコピー先の領域の一部が重複する場合、両方の関数では、重複する領域内の元のコピー元のバイトが上書きされる前に確実にコピーされます。

セキュリティに関する注意 移動先バッファーが移動された文字数に対応できる十分な大きさであることを確認してください。 詳しくは、「バッファー オーバーランの回避」をご覧ください。

次の例に示すように、memmove および wmemmove 関数は、#include ステートメントの前に定数 _CRT_SECURE_DEPRECATE_MEMORY が定義されている場合にのみ非推奨になります。

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <string.h>

または

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <wchar.h>

要件

ルーチンによって返される値 必須ヘッダー
memmove <string.h>
wmemmove <wchar.h>

互換性の詳細については、「 Compatibility」を参照してください。

// crt_memcpy.c
// Illustrate overlapping copy: memmove
// always handles it correctly; memcpy may handle
// it correctly.
//

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

char str1[7] = "aabbcc";

int main( void )
{
   printf( "The string: %s\n", str1 );
   memcpy( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );

   strcpy_s( str1, sizeof(str1), "aabbcc" );   // reset string

   printf( "The string: %s\n", str1 );
   memmove( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );
}
The string: aabbcc
New string: aaaabb
The string: aabbcc
New string: aaaabb

関連項目

バッファー操作
_memccpy
memcpywmemcpy
strcpywcscpy_mbscpy
strncpy_strncpy_lwcsncpy_wcsncpy_l_mbsncpy_mbsncpy_l