[net.sources] MEP and memcpy

jantypas@hope.UUCP (John Antypas) (10/14/86)

Some sites out there do not have BSD 4.3 or Sys V.  Those of you who
do will find the compiler will complain about a routine called memcpy.
This is basically a blockmove call.  If you have that, use it.  If
not, here is memcpy from a string package posted few months back.


/*
 * memcpy - copy bytes
 */

char *memcpy(dst, src, size)
char *dst;
char *src;
int size;
{
	register char *d;
	register char *s;
	register int n;

	if (size <= 0)
		return(dst);

	s = src;
	d = dst;
	if (s <= d && s + (size-1) >= d) {
		/* Overlap, must copy right-to-left. */
		s += size-1;
		d += size-1;
		for (n = size; n > 0; n--)
			*d-- = *s--;
	} else
		for (n = size; n > 0; n--)
			*d++ = *s++;

	return(dst);
}