[go: up one dir, main page]

File: byte_copy.c

package info (click to toggle)
fnord 1.9-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 328 kB
  • ctags: 167
  • sloc: ansic: 1,889; makefile: 99; sh: 62; perl: 36
file content (28 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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;
  register const char* u=t+len;
  if (len>127) {
    while ((unsigned long)s&(sizeof(unsigned long)-1)) {
      if (t==u) break; *s=*t; ++s; ++t;
    }
    /* 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;
	s+=sizeof(unsigned long); t+=sizeof(unsigned long);
      }
  }
  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;
  }
}