2001-02-02 17:54:47 +00:00
|
|
|
#include "byte.h"
|
|
|
|
|
|
|
|
/* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
|
|
|
|
* to out[len-1]. */
|
2003-08-26 17:58:14 +00:00
|
|
|
void byte_copy(void* out, unsigned long len, const void* in) {
|
2001-02-02 17:54:47 +00:00
|
|
|
register char* s=out;
|
|
|
|
register const char* t=in;
|
2001-11-25 22:54:00 +00:00
|
|
|
register const char* u=t+len;
|
2001-09-10 10:37:00 +00:00
|
|
|
if (len>127) {
|
2002-08-14 16:00:02 +00:00
|
|
|
while ((unsigned long)s&(sizeof(unsigned long)-1)) {
|
2002-08-14 15:54:49 +00:00
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
2002-08-14 16:00:02 +00:00
|
|
|
}
|
2002-08-14 15:54:49 +00:00
|
|
|
/* s (destination) is now unsigned long aligned */
|
|
|
|
#ifndef __i386__
|
2002-08-14 15:57:33 +00:00
|
|
|
if (!((unsigned long)t&(sizeof(unsigned long)-1)))
|
2002-08-14 15:54:49 +00:00
|
|
|
#endif
|
2002-08-14 15:57:33 +00:00
|
|
|
while (t+sizeof(unsigned long)<=u) {
|
|
|
|
*(unsigned long*)s=*(unsigned long*)t;
|
|
|
|
s+=sizeof(unsigned long); t+=sizeof(unsigned long);
|
|
|
|
}
|
|
|
|
}
|
2001-02-02 17:54:47 +00:00
|
|
|
for (;;) {
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
}
|
|
|
|
}
|