]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLib / CompareMemWrapper.c
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
14 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
15 SPDX-License-Identifier: BSD-2-Clause-Patent
16
17 **/
18
19 #include "MemLibInternals.h"
20
21 /**
22 Compares the contents of two buffers.
23
24 This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.
25 If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the
26 value returned is the first mismatched byte in SourceBuffer subtracted from the first
27 mismatched byte in DestinationBuffer.
28
29 If Length > 0 and DestinationBuffer is NULL, then ASSERT().
30 If Length > 0 and SourceBuffer is NULL, then ASSERT().
31 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().
32 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
33
34 @param DestinationBuffer A pointer to the destination buffer to compare.
35 @param SourceBuffer A pointer to the source buffer to compare.
36 @param Length The number of bytes to compare.
37
38 @return 0 All Length bytes of the two buffers are identical.
39 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
40 mismatched byte in DestinationBuffer.
41
42 **/
43 INTN
44 EFIAPI
45 CompareMem (
46 IN CONST VOID *DestinationBuffer,
47 IN CONST VOID *SourceBuffer,
48 IN UINTN Length
49 )
50 {
51 if (Length == 0 || DestinationBuffer == SourceBuffer) {
52 return 0;
53 }
54 ASSERT (DestinationBuffer != NULL);
55 ASSERT (SourceBuffer != NULL);
56 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));
57 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));
58
59 return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);
60 }