Reimplemented bzero, bcopy and memset again. The previous ones had

subtle errors which crashed things.
This commit is contained in:
jshepher 2004-12-04 22:38:39 +00:00
parent be3a110843
commit f5e2060927
3 changed files with 15 additions and 20 deletions

View File

@ -1,9 +1,12 @@
#include <stdlib.h>
#include <string.h>
/* This is a _fast_ block move routine! */
void bcopy(const void *s1,void *s2,size_t n)
{
memcpy(s2, s1, n);
unsigned char *ch1 = s1;
unsigned char *ch2 = s2;
while (n > 0) {
*ch2++ = *ch1++;
n--;
}
}

View File

@ -2,5 +2,9 @@
void bzero(void *b,size_t n)
{
memset(b, 0, n);
unsigned char *ch = (unsigned char *)b;
while (n > 0) {
*ch++ = 0;
n--;
}
}

View File

@ -2,22 +2,10 @@
void *memset(void *s,int c,size_t n)
{
unsigned long *p = (unsigned long *)s;
unsigned char chr = (unsigned char)c;
unsigned long lc = (chr << 24) | (chr << 16) | (chr << 8) | chr;
unsigned char *ch;
size_t i;
size_t num = n / 4;
size_t remain = n % 4;
/* Do LONG operations most of the time to optimize memory bandwidth */
for (i = 0; i < num; i++) {
*p++ = lc;
}
ch = (unsigned char *)p;
for (i = 0; i < remain; i++) {
*ch++ = chr;
unsigned char *ch = (unsigned char *)s;
while (n > 0) {
*ch++ = c;
n--;
}
return s;
}