memmove_s, wmemmove_s

バッファーを別のバッファーに移動します。 これらの関数は、CRTmemmovewmemmoveセキュリティ機能の説明に従ってセキュリティが強化されたバージョンの関数です。

構文

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 変更されない

解説

countからバイト数の文字をコピーしますdestsrc。 ソース領域とコピー先リージョンの一部が重複している場合は、 memmove_s 重複するリージョンの元のソース バイトが上書きされる前にコピーされるようにします。

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

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

必要条件

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

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

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

関連項目

バッファー操作
_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