home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / swab.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  51 lines

  1. /***
  2. *swab.c - block copy, while swapping even/odd bytes
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       This module contains the routine _swab() which swaps the odd/even
  8. *       bytes of words during a block copy.
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <stdlib.h>
  14.  
  15. /***
  16. *void _swab(srcptr, dstptr, nbytes) - swap ODD/EVEN bytes during word move
  17. *
  18. *Purpose:
  19. *       This routine copys a block of words and swaps the odd and even
  20. *       bytes.  nbytes must be > 0, otherwise nothing is copied.  If
  21. *       nbytes is odd, then only (nbytes-1) bytes are copied.
  22. *
  23. *Entry:
  24. *       srcptr = pointer to the source block
  25. *       dstptr = pointer to the destination block
  26. *       nbytes = number of bytes to swap
  27. *
  28. *Returns:
  29. *       None.
  30. *
  31. *Exceptions:
  32. *
  33. *******************************************************************************/
  34.  
  35. void __cdecl _swab (
  36.         char *src,
  37.         char *dest,
  38.         int nbytes
  39.         )
  40. {
  41.         char b1, b2;
  42.  
  43.         while (nbytes > 1) {
  44.                 b1 = *src++;
  45.                 b2 = *src++;
  46.                 *dest++ = b2;
  47.                 *dest++ = b1;
  48.                 nbytes -= 2;
  49.         }
  50. }
  51.