void* memove(void* dest,const void*src,size_t count) { assert((dest != NULL) && (src != NULL)); assert(count>0); char* psrc = (char*)src; char* pdest = (char*)dest; //检查是否有重叠问题 if(pdest < psrc) { //正向拷贝 while(count--) *pdest++ = *psrc++; } else if(psrc < pdest) { //反向拷贝 psrc = psrc + count -1; pdest = pdest + count -1; while(count--) *pdest-- = *psrc--; } return dest; } void* memmcpy(void* dest,const void* src,size_t count) { assert((dest != NULL) && (src != NULL)); assert(count > 0); char* psrc = (char*)src; char* pdest = (char*)dest; while(count --) *pdest++ = *psrc++; return dest; }
时间: 2024-10-10 06:54:18