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.

94 lines
2.2 KiB

  1. /***
  2. *memcmp.c - compare two blocks of memory
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines memcmp() - compare two memory blocks lexically and
  8. * find their order.
  9. *
  10. *Revision History:
  11. * 05-31-89 JCR C version created.
  12. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  13. * copyright.
  14. * 10-01-90 GJF New-style function declarator. Also, rewrote expr. to
  15. * avoid using cast as an lvalue.
  16. * 04-01-91 SRW Add #pragma function for i386 _WIN32_ and _CRUISER_
  17. * builds
  18. * 10-11-91 GJF Bug fix! Comparison of final bytes must use unsigned
  19. * chars.
  20. * 09-01-93 GJF Replaced _CALLTYPE1 with __cdecl.
  21. * 12-03-93 GJF Turn on #pragma function for all MS front-ends (esp.,
  22. * Alpha compiler).
  23. *
  24. *******************************************************************************/
  25. #include <cruntime.h>
  26. #include <string.h>
  27. #ifdef _MSC_VER
  28. #pragma function(memcmp)
  29. #endif
  30. /***
  31. *int memcmp(buf1, buf2, count) - compare memory for lexical order
  32. *
  33. *Purpose:
  34. * Compares count bytes of memory starting at buf1 and buf2
  35. * and find if equal or which one is first in lexical order.
  36. *
  37. *Entry:
  38. * void *buf1, *buf2 - pointers to memory sections to compare
  39. * size_t count - length of sections to compare
  40. *
  41. *Exit:
  42. * returns < 0 if buf1 < buf2
  43. * returns 0 if buf1 == buf2
  44. * returns > 0 if buf1 > buf2
  45. *
  46. *Exceptions:
  47. *
  48. *******************************************************************************/
  49. int __cdecl memcmp (
  50. const void * buf1,
  51. const void * buf2,
  52. size_t count
  53. )
  54. {
  55. if (!count)
  56. return(0);
  57. #if defined(_M_AMD64)
  58. {
  59. #if !defined(LIBCNTPR)
  60. __declspec(dllimport)
  61. #endif
  62. size_t RtlCompareMemory( const void * src1, const void * src2, size_t length );
  63. size_t length;
  64. if ( ( length = RtlCompareMemory( buf1, buf2, count ) ) == count ) {
  65. return(0);
  66. }
  67. buf1 = (char *)buf1 + length;
  68. buf2 = (char *)buf2 + length;
  69. }
  70. #else
  71. while ( --count && *(char *)buf1 == *(char *)buf2 ) {
  72. buf1 = (char *)buf1 + 1;
  73. buf2 = (char *)buf2 + 1;
  74. }
  75. #endif
  76. return( *((unsigned char *)buf1) - *((unsigned char *)buf2) );
  77. }