wm: teppich

ref: 48cc33b5b8717b83c4dea9130c4396b451480c56
dir: /libc/memcpy.c/

View raw version
void*
memcpy(void *a1, void *a2, unsigned int len)
{
	char *s1, *s2;

	s1 = a1;
	s2 = a2;
	if((s2 < s1) && (s2 + len > s1))
		goto back;
	while(len > 0) {
		*s1++ = *s2++;
		len--;
	}
	return a1;

back:
	s1 += len;
	s2 += len;
	while(len > 0) {
		*--s1 = *--s2;
		len--;
	}
	return a1;
}