memswap.c 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*====================================================================*
  2. *
  3. * void memswap (void * memory1, void * memory2, size_t extent);
  4. *
  5. * memory.h
  6. *
  7. * exchange the contents of one memory region with that of another;
  8. * return no value;
  9. *
  10. * one application for this function is to exchange the source and
  11. * destination addresses in an Ethernet frame to form a response
  12. * message;
  13. *
  14. * Motley Tools by Charles Maier;
  15. * Copyright (c) 2001-2006 by Charles Maier Associates;
  16. * Licensed under the Internet Software Consortium License;
  17. *
  18. *--------------------------------------------------------------------*/
  19. #ifndef MEMSWAP_SOURCE
  20. #define MEMSWAP_SOURCE
  21. #include "../tools/memory.h"
  22. void memswap (void * memory1, void * memory2, size_t extent)
  23. {
  24. register byte * byte1 = (byte *)(memory1);
  25. register byte * byte2 = (byte *)(memory2);
  26. if (memory1 != memory2) while (extent--)
  27. {
  28. byte byte = *byte1;
  29. *byte1++ = *byte2;
  30. *byte2++ = byte;
  31. }
  32. return;
  33. }
  34. #endif