gcc/libiberty/bcopy.c

32 lines
694 B
C
Raw Normal View History

1997-08-21 22:57:35 +00:00
/* bcopy -- copy memory regions of arbitary length
@deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
1997-08-21 22:57:35 +00:00
Copies @var{length} bytes from memory region @var{in} to region
@var{out}. The use of @code{bcopy} is deprecated in new programs.
1997-08-21 22:57:35 +00:00
@end deftypefn
1997-08-21 22:57:35 +00:00
*/
#include <stddef.h>
1997-08-21 22:57:35 +00:00
void
bcopy (const void *src, void *dest, size_t len)
1997-08-21 22:57:35 +00:00
{
if (dest < src)
{
const char *firsts = (const char *) src;
char *firstd = (char *) dest;
while (len--)
*firstd++ = *firsts++;
}
1997-08-21 22:57:35 +00:00
else
{
const char *lasts = (const char *)src + (len-1);
char *lastd = (char *)dest + (len-1);
1997-08-21 22:57:35 +00:00
while (len--)
*lastd-- = *lasts--;
1997-08-21 22:57:35 +00:00
}
}