2006-06-15 18:02:20 +02:00
|
|
|
#include "types.h"
|
2009-03-08 22:38:30 +01:00
|
|
|
#include "x86.h"
|
2006-06-15 18:02:20 +02:00
|
|
|
|
2006-09-06 19:27:19 +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
|
|
|
{
|
2009-03-08 22:38:30 +01:00
|
|
|
stosb(dst, c, n);
|
2006-06-12 17:22:12 +02:00
|
|
|
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
|
|
|
{
|
2007-08-10 19:17:42 +02:00
|
|
|
const uchar *s1, *s2;
|
|
|
|
|
|
|
|
s1 = v1;
|
|
|
|
s2 = v2;
|
2007-08-28 20:32:08 +02:00
|
|
|
while(n-- > 0){
|
2006-09-06 19:27:19 +02:00
|
|
|
if(*s1 != *s2)
|
2007-08-10 19:17:42 +02:00
|
|
|
return *s1 - *s2;
|
2006-06-21 03:53:07 +02:00
|
|
|
s1++, s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-06-22 03:28:57 +02:00
|
|
|
|
2006-09-06 19:27:19 +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;
|
2006-09-06 19:04:06 +02:00
|
|
|
|
2006-06-22 03:28:57 +02:00
|
|
|
s = src;
|
|
|
|
d = dst;
|
2007-08-28 20:32:08 +02:00
|
|
|
if(s < d && s + n > d){
|
2006-06-22 03:28:57 +02:00
|
|
|
s += n;
|
|
|
|
d += n;
|
2006-09-06 19:27:19 +02:00
|
|
|
while(n-- > 0)
|
2006-06-22 03:28:57 +02:00
|
|
|
*--d = *--s;
|
2007-08-28 20:37:41 +02:00
|
|
|
} else
|
2006-09-06 19:27:19 +02:00
|
|
|
while(n-- > 0)
|
2006-06-22 03:28:57 +02:00
|
|
|
*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
|
|
|
{
|
2006-09-06 19:27:19 +02:00
|
|
|
while(n > 0 && *p && *p == *q)
|
2006-09-06 19:04:06 +02:00
|
|
|
n--, p++, q++;
|
2006-09-06 19:27:19 +02:00
|
|
|
if(n == 0)
|
2006-09-06 19:04:06 +02:00
|
|
|
return 0;
|
2007-08-24 23:00:02 +02:00
|
|
|
return (uchar)*p - (uchar)*q;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
strncpy(char *s, const char *t, int n)
|
|
|
|
{
|
|
|
|
char *os;
|
|
|
|
|
|
|
|
os = s;
|
|
|
|
while(n-- > 0 && (*s++ = *t++) != 0)
|
|
|
|
;
|
|
|
|
while(n-- > 0)
|
|
|
|
*s++ = 0;
|
|
|
|
return os;
|
2006-07-05 22:00:14 +02:00
|
|
|
}
|
2007-08-08 10:37:22 +02:00
|
|
|
|
|
|
|
// Like strncpy but guaranteed to NUL-terminate.
|
|
|
|
char*
|
|
|
|
safestrcpy(char *s, const char *t, int n)
|
|
|
|
{
|
|
|
|
char *os;
|
|
|
|
|
|
|
|
os = s;
|
|
|
|
if(n <= 0)
|
|
|
|
return os;
|
|
|
|
while(--n > 0 && (*s++ = *t++) != 0)
|
|
|
|
;
|
|
|
|
*s = 0;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2007-08-21 21:22:08 +02:00
|
|
|
int
|
|
|
|
strlen(const char *s)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for(n = 0; s[n]; n++)
|
|
|
|
;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|