2006-06-15 18:02:20 +02:00
|
|
|
#include "types.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
2006-06-12 17:22:12 +02:00
|
|
|
void *
|
2006-07-17 03:52:13 +02:00
|
|
|
memset(void *dst, int c, uint n)
|
2006-06-12 17:22:12 +02:00
|
|
|
{
|
|
|
|
char *d = (char *) dst;
|
|
|
|
|
|
|
|
while(n-- > 0)
|
|
|
|
*d++ = c;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
2006-06-21 03:53:07 +02:00
|
|
|
|
|
|
|
int
|
2006-07-17 03:52:13 +02:00
|
|
|
memcmp(const void *v1, const void *v2, uint n)
|
2006-06-21 03:53:07 +02:00
|
|
|
{
|
2006-07-20 11:07:53 +02:00
|
|
|
const uchar *s1 = (const uchar *) v1;
|
|
|
|
const uchar *s2 = (const uchar *) v2;
|
2006-06-21 03:53:07 +02:00
|
|
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
if (*s1 != *s2)
|
|
|
|
return (int) *s1 - (int) *s2;
|
|
|
|
s1++, s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-06-22 03:28:57 +02:00
|
|
|
|
|
|
|
void *
|
2006-07-17 03:52:13 +02:00
|
|
|
memmove(void *dst, const void *src, uint n)
|
2006-06-22 03:28:57 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2006-07-05 22:00:14 +02:00
|
|
|
|
|
|
|
int
|
2006-07-17 03:52:13 +02:00
|
|
|
strncmp(const char *p, const char *q, uint n)
|
2006-07-05 22:00:14 +02:00
|
|
|
{
|
|
|
|
while (n > 0 && *p && *p == *q)
|
|
|
|
n--, p++, q++;
|
|
|
|
if (n == 0)
|
|
|
|
return 0;
|
|
|
|
else
|
2006-07-20 11:07:53 +02:00
|
|
|
return (int) ((uchar) *p - (uchar) *q);
|
2006-07-05 22:00:14 +02:00
|
|
|
}
|
2006-07-16 03:47:40 +02:00
|
|
|
|
|
|
|
// Memcpy is deprecated and should NOT be called.
|
|
|
|
// Use memmove instead, which has defined semantics
|
|
|
|
// when the two memory ranges overlap.
|
|
|
|
// Memcpy is here only because gcc compiles some
|
|
|
|
// structure assignments into calls to memcpy.
|
|
|
|
void *
|
2006-07-17 03:52:13 +02:00
|
|
|
memcpy(void *dst, void *src, uint n)
|
2006-07-16 03:47:40 +02:00
|
|
|
{
|
|
|
|
char *d = (char *) dst;
|
|
|
|
char *s = (char *) src;
|
|
|
|
|
|
|
|
while(n-- > 0)
|
|
|
|
*d++ = *s++;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|