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