201306121520memset/memcpy/memcmp --- 簡單的實作

 void *memset(void *s, char c, unsigned long n)
{
unsigned long  i;
char *ss = (char *)s;

for (i = 0; i < n; i++) ss[i] = (char)c;
return s;
}

void *memcpy(void *dest, const void *src, unsigned long count)
{
char *tmp = dest;
const char *s = src;

while (count--)
*tmp++ = *s++;
return dest;
}

int memcmp(const void *cs, const void *ct, unsigned long count)
{
const unsigned char *su1, *su2;
int res = 0;

for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
}

沒有上一則|日誌首頁|沒有下一則
回應





Powered by Xuite
    沒有新回應!
關鍵字