Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

  1. /***
  2. *swab.c - block copy, while swapping even/odd bytes
  3. *
  4. * Copyright (c) 1989-2001, 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. *Revision History:
  11. * 06-02-89 PHG module created, based on asm version
  12. * 03-06-90 GJF Fixed calling type, added #include <cruntime.h> and
  13. * fixed copyright. Also, cleaned up the formatting a
  14. * bit.
  15. * 09-27-90 GJF New-style function declarators.
  16. * 01-21-91 GJF ANSI naming.
  17. * 04-06-93 SKS Replace _CRTAPI* with _cdecl
  18. *
  19. *******************************************************************************/
  20. #include <cruntime.h>
  21. #include <stdlib.h>
  22. /***
  23. *void _swab(srcptr, dstptr, nbytes) - swap ODD/EVEN bytes during word move
  24. *
  25. *Purpose:
  26. * This routine copys a block of words and swaps the odd and even
  27. * bytes. nbytes must be > 0, otherwise nothing is copied. If
  28. * nbytes is odd, then only (nbytes-1) bytes are copied.
  29. *
  30. *Entry:
  31. * srcptr = pointer to the source block
  32. * dstptr = pointer to the destination block
  33. * nbytes = number of bytes to swap
  34. *
  35. *Returns:
  36. * None.
  37. *
  38. *Exceptions:
  39. *
  40. *******************************************************************************/
  41. void __cdecl _swab (
  42. char *src,
  43. char *dest,
  44. int nbytes
  45. )
  46. {
  47. char b1, b2;
  48. while (nbytes > 1) {
  49. b1 = *src++;
  50. b2 = *src++;
  51. *dest++ = b2;
  52. *dest++ = b1;
  53. nbytes -= 2;
  54. }
  55. }