72 lines
1.3 KiB
C
72 lines
1.3 KiB
C
#include <types.h>
|
|
|
|
void *memmove(void *dest, const void *src, size_t size)
|
|
{
|
|
char *tmp, *s;
|
|
|
|
if (src < dest) {
|
|
tmp = (char *) dest + size;
|
|
s = (char *) src + size;
|
|
for (; size; size--)
|
|
*--tmp = *--s;
|
|
} else {
|
|
tmp = (char *) dest;
|
|
s = (char *) src;
|
|
for (; size; size--)
|
|
*tmp++ = *s++;
|
|
}
|
|
|
|
return dest;
|
|
}
|
|
|
|
#ifndef __HAVE_ARCH_MEMSET
|
|
/**
|
|
* memset - Fill a region of memory with the given value
|
|
* @s: Pointer to the start of the area.
|
|
* @c: The byte to fill the area with
|
|
* @count: The size of the area.
|
|
*
|
|
* Do not use memset() to access IO space, use memset_io() instead.
|
|
*/
|
|
void * memset(void * s,int c,size_t count)
|
|
{
|
|
unsigned long *sl = (unsigned long *) s;
|
|
unsigned long cl = 0;
|
|
char *s8;
|
|
int i;
|
|
|
|
/* do it one word at a time (32 bits or 64 bits) while possible */
|
|
if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
|
|
for (i = 0; i < sizeof(*sl); i++) {
|
|
cl <<= 8;
|
|
cl |= c & 0xff;
|
|
}
|
|
while (count >= sizeof(*sl)) {
|
|
*sl++ = cl;
|
|
count -= sizeof(*sl);
|
|
}
|
|
}
|
|
/* fill 8 bits at a time */
|
|
s8 = (char *)sl;
|
|
while (count--)
|
|
*s8++ = c;
|
|
|
|
return s;
|
|
}
|
|
|
|
#ifndef __HAVE_ARCH_STRLEN
|
|
/**
|
|
* strlen - Find the length of a string
|
|
* @s: The string to be sized
|
|
*/
|
|
size_t strlen(const char * s)
|
|
{
|
|
const char *sc;
|
|
|
|
for (sc = s; *sc != '\0'; ++sc)
|
|
/* nothing */;
|
|
return sc - s;
|
|
}
|
|
#endif
|
|
|
|
#endif |