1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Utility                                                             */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _ux_utility_memory_compare                          PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Chaoqiong Xiao, Microsoft Corporation                               */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function compares two memory blocks.                           */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    memory_source                         Pointer to source             */
47 /*    memory_destination                    Pointer to destination        */
48 /*    length                                Number of bytes to compare    */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    UX_SUCCESS                            If blocks are equal           */
53 /*    UX_ERROR                              If blocks are not equal       */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    USBX Components                                                     */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_ux_utility_memory_compare(VOID * memory_source,VOID * memory_destination,ULONG length)72 UINT  _ux_utility_memory_compare(VOID *memory_source, VOID *memory_destination, ULONG length)
73 {
74 
75 UCHAR *   source;
76 UCHAR *   destination;
77 
78 
79     /* Setup source and destination byte oriented pointers.  */
80     source =  (UCHAR *) memory_source;
81     destination =  (UCHAR *) memory_destination;
82 
83     /* Loop to compare blocks.  */
84     while(length--)
85     {
86 
87         /* Compare a single byte.  */
88         if(*destination++ != *source++)
89         {
90 
91             /* Not equal, return an error.  */
92             return(UX_ERROR);
93         }
94     }
95 
96     /* Blocks are equal, return success.  */
97     return(UX_SUCCESS);
98 }
99 
100