Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
839 B

  1. #include "byte.h"
  2. /* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
  3. * to out[len-1]. */
  4. void byte_copy(void* out, unsigned int len, const void* in) {
  5. register char* s=out;
  6. register const char* t=in;
  7. register const char* u=in+len;
  8. if (len>127) {
  9. if (sizeof(unsigned long)>4) { /* a good compiler should optimize this check away */
  10. for (;(unsigned long)t&7;) {
  11. if (t==u) break; *s=*t; ++s; ++t;
  12. }
  13. } else {
  14. for (;(unsigned long)t&3;) {
  15. if (t==u) break; *s=*t; ++s; ++t;
  16. }
  17. }
  18. while (t+sizeof(long)<=u) {
  19. *(unsigned long*)s=*(unsigned long*)t;
  20. s+=sizeof(long); t+=sizeof(long);
  21. }
  22. }
  23. for (;;) {
  24. if (t==u) break; *s=*t; ++s; ++t;
  25. if (t==u) break; *s=*t; ++s; ++t;
  26. if (t==u) break; *s=*t; ++s; ++t;
  27. if (t==u) break; *s=*t; ++s; ++t;
  28. }
  29. }