libowfat/byte/byte_copy.c

28 lines
830 B
C
Raw Normal View History

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]. */
void byte_copy(void* out, unsigned int len, const void* in) {
register char* s=out;
register const char* t=in;
2001-11-25 22:54:00 +00:00
register const char* u=t+len;
if (len>127) {
2002-08-14 15:54:49 +00:00
while ((unsigned long)s&(sizeof(unsigned long)-1))
if (t==u) break; *s=*t; ++s; ++t;
}
2002-08-14 15:54:49 +00:00
/* s (destination) is now unsigned long aligned */
#ifndef __i386__
if (!((unsigned long)t&(sizeof(unsigned long)-1)))
#endif
while (t+sizeof(unsigned long)<=u) {
*(unsigned long*)s=*(unsigned long*)t;
2002-08-14 15:54:49 +00:00
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;
}
}