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