bcopy.c 694 B

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