标签:
#include <iostream> #include <string.h> using namespace std; void* memmove(void *dst, const void *src, size_t count){ // 容错处理 if (dst == NULL || src == NULL){ return NULL; } unsigned char *pdst = (unsigned char *)dst; const unsigned char *psrc = (const unsigned char *)src; //判断内存是否重叠 bool flag1 = (pdst >= psrc && pdst < psrc + count); bool flag2 = (psrc >= pdst && psrc < pdst + count); if (flag1 || flag2){ // 倒序拷贝 while (count){ *(pdst + count - 1) = *(psrc + count - 1); count--; }//while } else{ // 拷贝 while (count--){ *pdst = *psrc; pdst++; psrc++; }//while } return dst; }
标签:
原文地址:http://blog.csdn.net/yangshuangtao/article/details/46633435