xref: /netbsd/external/gpl3/gdb/dist/libiberty/bcopy.c (revision c5dff60a)
1*c5dff60aSchristos /* bcopy -- copy memory regions of arbitary length
2*c5dff60aSchristos 
3*c5dff60aSchristos @deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
4*c5dff60aSchristos 
5*c5dff60aSchristos Copies @var{length} bytes from memory region @var{in} to region
6*c5dff60aSchristos @var{out}.  The use of @code{bcopy} is deprecated in new programs.
7*c5dff60aSchristos 
8*c5dff60aSchristos @end deftypefn
9*c5dff60aSchristos 
10*c5dff60aSchristos */
11*c5dff60aSchristos 
12*c5dff60aSchristos #include <stddef.h>
13*c5dff60aSchristos 
14*c5dff60aSchristos void
bcopy(const void * src,void * dest,size_t len)15*c5dff60aSchristos bcopy (const void *src, void *dest, size_t len)
16*c5dff60aSchristos {
17*c5dff60aSchristos   if (dest < src)
18*c5dff60aSchristos     {
19*c5dff60aSchristos       const char *firsts = (const char *) src;
20*c5dff60aSchristos       char *firstd = (char *) dest;
21*c5dff60aSchristos       while (len--)
22*c5dff60aSchristos 	*firstd++ = *firsts++;
23*c5dff60aSchristos     }
24*c5dff60aSchristos   else
25*c5dff60aSchristos     {
26*c5dff60aSchristos       const char *lasts = (const char *)src + (len-1);
27*c5dff60aSchristos       char *lastd = (char *)dest + (len-1);
28*c5dff60aSchristos       while (len--)
29*c5dff60aSchristos         *lastd-- = *lasts--;
30*c5dff60aSchristos     }
31*c5dff60aSchristos }
32