]>
Commit | Line | Data |
---|---|---|
28e9041c | 1 | /* bcopy -- copy memory regions of arbitary length |
2 | ||
614a23c6 | 3 | @deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length}) |
28e9041c | 4 | |
614a23c6 | 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. | |
28e9041c | 7 | |
614a23c6 | 8 | @end deftypefn |
28e9041c | 9 | |
10 | */ | |
11 | ||
943c390a | 12 | #include <stddef.h> |
13 | ||
28e9041c | 14 | void |
943c390a | 15 | bcopy (const void *src, void *dest, size_t len) |
28e9041c | 16 | { |
17 | if (dest < src) | |
943c390a | 18 | { |
19 | const char *firsts = src; | |
20 | char *firstd = dest; | |
21 | while (len--) | |
22 | *firstd++ = *firsts++; | |
23 | } | |
28e9041c | 24 | else |
25 | { | |
943c390a | 26 | const char *lasts = (const char *)src + (len-1); |
27 | char *lastd = (char *)dest + (len-1); | |
28e9041c | 28 | while (len--) |
943c390a | 29 | *lastd-- = *lasts--; |
28e9041c | 30 | } |
31 | } |