:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / ntdll / rtl / mem.c
1 /* $Id$
2  * 
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            kernel/rtl/mem.c
6  * PURPOSE:         Memory functions
7  * PROGRAMMER:      David Welch (welch@mcmail.com)
8  * UPDATE HISTORY:
9  *                  Created 22/05/98
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <string.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19 ULONG
20 STDCALL
21 RtlCompareMemory(PVOID Source1, PVOID Source2, ULONG Length)
22 /*
23  * FUNCTION: Compares blocks of memory and returns the number of equal bytes
24  * ARGUMENTS:
25  *      Source1 = Block to compare
26  *      Source2 = Block to compare
27  *      Length = Number of bytes to compare
28  * RETURNS: Number of equal bytes
29  */
30 {
31    int i,total;
32    
33    for (i=0,total=0;i<Length;i++)
34      {
35         if ( ((PUCHAR)Source1)[i] == ((PUCHAR)Source2)[i] )
36           {
37              total++;
38           }
39      }
40    return(total);
41 }
42
43 ULONG
44 STDCALL
45 RtlCompareMemoryUlong (
46         PVOID   Source,
47         ULONG   Length,
48         ULONG   Value
49         )
50 /*
51  * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
52  * ARGUMENTS:
53  *      Source = Block to compare
54  *      Length = Number of bytes to compare
55  *      Value = Value to compare
56  * RETURNS: Number of equal bytes
57  */
58 {
59         PULONG ptr = (PULONG)Source;
60         ULONG  len = Length / sizeof(ULONG);
61         int i;
62
63         for (i = 0; i < len; i++)
64         {
65                 if (*ptr != Value)
66                         break;
67                 ptr++;
68         }
69
70         return (ULONG)((PCHAR)ptr - (PCHAR)Source);
71 }
72
73 #if 0
74 VOID RtlCopyBytes(PVOID Destination,
75                   CONST VOID* Source,
76                   ULONG Length)
77 {
78    RtlCopyMemory(Destination,Source,Length);
79 }
80
81 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
82 {
83    DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
84           Destination,Source,Length);
85    memcpy(Destination,Source,Length);
86    DPRINT("*Destination %x\n",*(PULONG)Destination);
87 }
88 #endif
89
90 VOID 
91 STDCALL
92 RtlFillMemory (
93         PVOID   Destination,
94         ULONG   Length,
95         UCHAR   Fill
96         )
97 {
98         memset (
99                 Destination,
100                 Fill,
101                 Length
102                 );
103 }
104
105 VOID
106 STDCALL
107 RtlFillMemoryUlong (
108         PVOID   Destination,
109         ULONG   Length,
110         ULONG   Fill
111         )
112 {
113         PULONG Dest  = Destination;
114         ULONG  Count = Length / sizeof(ULONG);
115
116         while (Count > 0)
117         {
118                 *Dest = Fill;
119                 Dest++;
120                 Count--;
121         }
122 }
123
124
125 VOID
126 STDCALL
127 RtlZeroMemory (
128         PVOID   Destination,
129         ULONG   Length
130         )
131 {
132         RtlFillMemory (
133                 Destination,
134                 Length,
135                 0
136                 );
137 }
138
139
140 VOID
141 STDCALL
142 RtlMoveMemory (
143         PVOID           Destination,
144         CONST VOID      * Source,
145         ULONG           Length
146         )
147 {
148         memmove (
149                 Destination,
150                 Source,
151                 Length
152                 );
153 }
154
155
156 /* EOF */