#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
void* mymemmove(void* dest, const void* src, const size_t count)
{
if (0 == count)
{
return NULL;
}
if (NULL == dest || NULL == src)
{
return NULL;
}
char* psrc = (char*)src;
char* pdest = (char*)dest;
if (pdest <= psrc || pdest > psrc + count)//没有覆盖的情况
{
cout << "overlapping" << endl;
for (size_t i = 0; i < count; i++)
{
*pdest = *psrc;
pdest++;
psrc++;
}
}
else//覆盖的情况
{
pdest = pdest + count;
psrc = psrc + count;
for (size_t i = 0; i < count; i++)
{
pdest--;
psrc--;
*pdest = *psrc;
}
}
return dest;
}
当复制片段没有重复的时候memmove和memcpy相同
C库中的memmove()函数的实现
最新推荐文章于 2022-03-27 21:08:09 发布