CompareMemWrapper.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /** @file
  2. CompareMem() implementation.
  3. The following BaseMemoryLib instances contain the same copy of this file:
  4. BaseMemoryLib
  5. BaseMemoryLibMmx
  6. BaseMemoryLibSse2
  7. BaseMemoryLibRepStr
  8. BaseMemoryLibOptDxe
  9. BaseMemoryLibOptPei
  10. PeiMemoryLib
  11. UefiMemoryLib
  12. Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
  13. This program and the accompanying materials
  14. are licensed and made available under the terms and conditions of the BSD License
  15. which accompanies this distribution. The full text of the license may be found at
  16. http://opensource.org/licenses/bsd-license.php
  17. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  18. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  19. **/
  20. #include "MemLibInternals.h"
  21. /**
  22. Compares the contents of two buffers.
  23. This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.
  24. If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the
  25. value returned is the first mismatched byte in SourceBuffer subtracted from the first
  26. mismatched byte in DestinationBuffer.
  27. If Length > 0 and DestinationBuffer is NULL, then ASSERT().
  28. If Length > 0 and SourceBuffer is NULL, then ASSERT().
  29. If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().
  30. If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
  31. @param DestinationBuffer Pointer to the destination buffer to compare.
  32. @param SourceBuffer Pointer to the source buffer to compare.
  33. @param Length Number of bytes to compare.
  34. @return 0 All Length bytes of the two buffers are identical.
  35. @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
  36. mismatched byte in DestinationBuffer.
  37. **/
  38. INTN
  39. EFIAPI
  40. CompareMem (
  41. IN CONST VOID *DestinationBuffer,
  42. IN CONST VOID *SourceBuffer,
  43. IN UINTN Length
  44. )
  45. {
  46. if (Length == 0 || DestinationBuffer == SourceBuffer) {
  47. return 0;
  48. }
  49. ASSERT (DestinationBuffer != NULL);
  50. ASSERT (SourceBuffer != NULL);
  51. ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));
  52. ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));
  53. return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);
  54. }