將某個緩衝區移到另一個緩衝區。 這些函式是 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 請確定重疊區域中的原始來源位元組會在覆寫之前先複製。
如果 或 如果 src dest 為 Null 指標,或目的地字串太小,則這些函式會叫用無效的參數處理程式,如參數驗證中所述。 如果允許繼續執行,這些函式會傳回 EINVAL,並將 errno 設為 EINVAL。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 常式 | 必要的標頭 |
|---|---|
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);
}
輸出
Before: 0123456789
After: 0012345789
另請參閱
緩衝區操作
_memccpy
memcpy, wmemcpy
strcpy_s、 、 wcscpy_s_mbscpy_s
strcpy、 、 wcscpy_mbscpy
strncpy_s、、_strncpy_s_lwcsncpy_s、_wcsncpy_s_l、、_mbsncpy_s、_mbsncpy_s_l
strncpy、、_strncpy_lwcsncpy、_wcsncpy_l、、_mbsncpy、_mbsncpy_l