2006-06-15 16:02:20 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
2006-06-12 15:22:12 +00:00
|
|
|
void *
|
|
|
|
memcpy(void *dst, void *src, unsigned n)
|
|
|
|
{
|
|
|
|
char *d = (char *) dst;
|
|
|
|
char *s = (char *) src;
|
|
|
|
|
|
|
|
while(n-- > 0)
|
|
|
|
*d++ = *s++;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
memset(void *dst, int c, unsigned n)
|
|
|
|
{
|
|
|
|
char *d = (char *) dst;
|
|
|
|
|
|
|
|
while(n-- > 0)
|
|
|
|
*d++ = c;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
2006-06-21 01:53:07 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
memcmp(const void *v1, const void *v2, unsigned n)
|
|
|
|
{
|
|
|
|
const uint8_t *s1 = (const uint8_t *) v1;
|
|
|
|
const uint8_t *s2 = (const uint8_t *) v2;
|
|
|
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
if (*s1 != *s2)
|
|
|
|
return (int) *s1 - (int) *s2;
|
|
|
|
s1++, s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-06-22 01:28:57 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
memmove(void *dst, const void *src, unsigned n)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
char *d;
|
|
|
|
|
|
|
|
s = src;
|
|
|
|
d = dst;
|
|
|
|
if (s < d && s + n > d) {
|
|
|
|
s += n;
|
|
|
|
d += n;
|
|
|
|
while (n-- > 0)
|
|
|
|
*--d = *--s;
|
|
|
|
} else
|
|
|
|
while (n-- > 0)
|
|
|
|
*d++ = *s++;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|