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

  1. /***
  2. *memcmp.c - compare two blocks of memory
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines memcmp() - compare two memory blocks lexically and
  8. *       find their order.
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. #ifdef _MSC_VER
  16. #pragma function(memcmp)
  17. #endif  /* _MSC_VER */
  18.  
  19. /***
  20. *int memcmp(buf1, buf2, count) - compare memory for lexical order
  21. *
  22. *Purpose:
  23. *       Compares count bytes of memory starting at buf1 and buf2
  24. *       and find if equal or which one is first in lexical order.
  25. *
  26. *Entry:
  27. *       void *buf1, *buf2 - pointers to memory sections to compare
  28. *       size_t count - length of sections to compare
  29. *
  30. *Exit:
  31. *       returns < 0 if buf1 < buf2
  32. *       returns  0  if buf1 == buf2
  33. *       returns > 0 if buf1 > buf2
  34. *
  35. *Exceptions:
  36. *
  37. *******************************************************************************/
  38.  
  39. int __cdecl memcmp (
  40.         const void * buf1,
  41.         const void * buf2,
  42.         size_t count
  43.         )
  44. {
  45.         if (!count)
  46.                 return(0);
  47.  
  48.         while ( --count && *(char *)buf1 == *(char *)buf2 ) {
  49.                 buf1 = (char *)buf1 + 1;
  50.                 buf2 = (char *)buf2 + 1;
  51.         }
  52.  
  53.         return( *((unsigned char *)buf1) - *((unsigned char *)buf2) );
  54. }
  55.