Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | /* bcopy -- copy memory regions of arbitary length |
2 | ||
39423523 | 3 | @deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length}) |
252b5132 | 4 | |
39423523 DD |
5 | Copies @var{length} bytes from memory region @var{in} to region |
6 | @var{out}. The use of @code{bcopy} is deprecated in new programs. | |
252b5132 | 7 | |
39423523 | 8 | @end deftypefn |
252b5132 RH |
9 | |
10 | */ | |
11 | ||
14a88c49 DD |
12 | #include <stddef.h> |
13 | ||
252b5132 | 14 | void |
14a88c49 | 15 | bcopy (const void *src, void *dest, size_t len) |
252b5132 RH |
16 | { |
17 | if (dest < src) | |
14a88c49 | 18 | { |
3ac01eb2 DD |
19 | const char *firsts = (const char *) src; |
20 | char *firstd = (char *) dest; | |
14a88c49 DD |
21 | while (len--) |
22 | *firstd++ = *firsts++; | |
23 | } | |
252b5132 RH |
24 | else |
25 | { | |
14a88c49 DD |
26 | const char *lasts = (const char *)src + (len-1); |
27 | char *lastd = (char *)dest + (len-1); | |
252b5132 | 28 | while (len--) |
14a88c49 | 29 | *lastd-- = *lasts--; |
252b5132 RH |
30 | } |
31 | } |