Share via


memmove_s、wmemmove_s

更新 : 2007 年 11 月

バッファの内容をほかのバッファに移動します。これらの関数は、「CRT のセキュリティ強化」に説明されているように、memmove、wmemmove のセキュリティが強化されたバージョンです。

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
    コピー先のオブジェクト。

  • numberOfElements
    コピー先のバッファのサイズ。

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

  • count
    コピーするバイト数 (memmove_s) または文字数 (wmemmove_s)。

戻り値

正常終了した場合は 0 を返します。失敗した場合はエラー コードを返します。

エラー条件

dest

numberOfElements

src

戻り値

dest の内容

NULL

any

any

EINVAL

変更されない

any

any

NULL

EINVAL

変更されない

any

< count

any

ERANGE

変更されない

解説

src から dest に count バイトの文字をコピーします。コピー元とコピー先の領域の一部が重なり合っている場合、memmove_s 関数は、重なり合っている領域のコピー元の内容をコピーした後で上書きを行います。

dest または src が null ポインタの場合、またはコピー先文字列が小さすぎる場合は、「パラメータの検証」に説明されているように、無効なパラメータ ハンドラが呼び出されます。実行の継続が許可された場合、これらの関数は EINVAL を返し、errno を EINVAL に設定します。

必要条件

ルーチン

必須ヘッダー

memmove_s

<string.h>

wmemmove_s

<wchar.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

使用例

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

.NET Framework の相当するアイテム

System::Buffer::BlockCopy

参照

参照

バッファ操作

_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