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.

54 lines
1.4 KiB

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