Rewrote function to get rid of GCC 3.x warnings.

This commit is contained in:
jshepher
2004-12-04 00:50:37 +00:00
parent a87d16a4f6
commit 5ed58ad13e
+18 -22
View File
@@ -1,27 +1,23 @@
#include <string.h> #include <string.h>
void *memset(void *s,int c,size_t n) void *memset(void *s,int c,size_t n)
{ size_t m; {
if(n) unsigned long *p = (unsigned long *)s;
{ unsigned long *p=(unsigned long *)s; unsigned char chr = (unsigned char)c;
if(n>15) unsigned long lc = (chr << 24) | (chr << 16) | (chr << 8) | chr;
{ c*=0x01010101; unsigned char *ch;
if((long)p&1) size_t i;
{ *((char *)p)++=c; size_t num = n / 4;
n--; } size_t remain = n % 4;
if((long)p&2)
{ *((short *)p)++=c; /* Do LONG operations most of the time to optimize memory bandwidth */
n-=2; } for (i = 0; i < num; i++) {
for(m=n/(8*sizeof(long));m;--m) *p++ = lc;
{ *p++=c; *p++=c; *p++=c; *p++=c;
*p++=c; *p++=c; *p++=c; *p++=c; }
n&=(8*sizeof(long)-1);
for(m=n/sizeof(long);m;--m)
*p++=c;
if((n&=sizeof(long)-1)==0) goto leave;
} }
do;while(*((char *)p)++=c,--n);
} ch = (unsigned char *)p;
leave: for (i = 0; i < remain; i++) {
return s; *ch++ = chr;
}
return s;
} }