binutils-gdb/libiberty/bcopy.c

32 lines
670 B
C
Raw Normal View History

1999-05-03 09:29:11 +02:00
/* bcopy -- copy memory regions of arbitary length
2001-09-26 20:45:50 +02:00
@deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
1999-05-03 09:29:11 +02:00
2001-09-26 20:45:50 +02:00
Copies @var{length} bytes from memory region @var{in} to region
@var{out}. The use of @code{bcopy} is deprecated in new programs.
1999-05-03 09:29:11 +02:00
2001-09-26 20:45:50 +02:00
@end deftypefn
1999-05-03 09:29:11 +02:00
*/
2005-04-03 06:41:10 +02:00
#include <stddef.h>
1999-05-03 09:29:11 +02:00
void
2005-04-03 06:41:10 +02:00
bcopy (const void *src, void *dest, size_t len)
1999-05-03 09:29:11 +02:00
{
if (dest < src)
2005-04-03 06:41:10 +02:00
{
const char *firsts = src;
char *firstd = dest;
while (len--)
*firstd++ = *firsts++;
}
1999-05-03 09:29:11 +02:00
else
{
2005-04-03 06:41:10 +02:00
const char *lasts = (const char *)src + (len-1);
char *lastd = (char *)dest + (len-1);
1999-05-03 09:29:11 +02:00
while (len--)
2005-04-03 06:41:10 +02:00
*lastd-- = *lasts--;
1999-05-03 09:29:11 +02:00
}
}