memmove_s wmemmove_s
將一個緩衝區移至另一個。 這些是舊版memmove wmemmove中所述的安全性增強功能與安全性功能,則在 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
目的地物件。numberOfElements
目的地緩衝區的大小。src
來源物件。count
位元組數目 (memmove_s) 或字元 (wmemmove_s) 來複製。
傳回值
如果成功 ;,零 在失敗的錯誤碼
錯誤狀況
dest |
numberOfElements |
src |
傳回值 |
內容dest |
---|---|---|---|---|
NULL |
任何 |
任何 |
EINVAL |
不能修改 |
任何 |
任何 |
NULL |
EINVAL |
不能修改 |
任何 |
< count |
任何 |
ERANGE |
不能修改 |
備註
複製count個位元組的字元從src到dest*.* 如果來源] 區域中的色彩和目的端的某些區域發生重疊, memmove_s可確保在重疊的區域中的原始來源位元組會被複製之前遭到覆寫。
如果dest或src時發現 null 指標,或者如果目的字串太小,這些函式叫用無效的參數處理常式中所述參數驗證 。 如果執行則允許繼續執行,則這些函數會傳回EINVAL ,並設定errno到EINVAL。
需求
常式 |
所需的標頭 |
---|---|
memmove_s |
<string.h> |
wmemmove_s |
<wchar.h> |
其他的相容性資訊,請參閱相容性在簡介中。
範例
// 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
.NET Framework 對等用法
請參閱
參考
strncpy_s、 _strncpy_s_l、 wcsncpy_s、 _wcsncpy_s_l、 _mbsncpy_s、 _mbsncpy_s_l
strncpy、 _strncpy_l、 wcsncpy、 _wcsncpy_l、 _mbsncpy、 _mbsncpy_l