ae59215c383c88d6b641a08a01b1386f4b295913
[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,
22         PVOID Source2,
23         ULONG Length)
24 /*
25  * FUNCTION: Compares blocks of memory and returns the number of equal bytes
26  * ARGUMENTS:
27  *      Source1 = Block to compare
28  *      Source2 = Block to compare
29  *      Length = Number of bytes to compare
30  * RETURNS: Number of equal bytes
31  */
32 {
33    int i,total;
34    
35    for (i=0,total=0;i<Length;i++)
36      {
37         if ( ((PUCHAR)Source1)[i] == ((PUCHAR)Source2)[i] )
38           {
39              total++;
40           }
41      }
42    return(total);
43 }
44
45 /*
46  * @implemented
47  */
48 ULONG
49 STDCALL
50 RtlCompareMemoryUlong (
51         PVOID   Source,
52         ULONG   Length,
53         ULONG   Value
54         )
55 /*
56  * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
57  * ARGUMENTS:
58  *      Source = Block to compare
59  *      Length = Number of bytes to compare
60  *      Value = Value to compare
61  * RETURNS: Number of equal bytes
62  */
63 {
64         PULONG ptr = (PULONG)Source;
65         ULONG  len = Length / sizeof(ULONG);
66         int i;
67
68         for (i = 0; i < len; i++)
69         {
70                 if (*ptr != Value)
71                         break;
72                 ptr++;
73         }
74
75         return (ULONG)((PCHAR)ptr - (PCHAR)Source);
76 }
77
78 #if 0
79 VOID RtlCopyBytes(PVOID Destination,
80                   CONST VOID* Source,
81                   ULONG Length)
82 {
83    RtlCopyMemory(Destination,Source,Length);
84 }
85
86 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
87 {
88    DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
89           Destination,Source,Length);
90    memcpy(Destination,Source,Length);
91    DPRINT("*Destination %x\n",*(PULONG)Destination);
92 }
93 #endif
94
95 /*
96  * @implemented
97  */
98 VOID 
99 STDCALL
100 RtlFillMemory (
101         PVOID   Destination,
102         ULONG   Length,
103         UCHAR   Fill
104         )
105 {
106         memset(Destination, Fill, Length);
107 }
108
109 /*
110  * @implemented
111  */
112 VOID
113 STDCALL
114 RtlFillMemoryUlong (
115         PVOID   Destination,
116         ULONG   Length,
117         ULONG   Fill
118         )
119 {
120         PULONG Dest  = Destination;
121         ULONG  Count = Length / sizeof(ULONG);
122
123         while (Count > 0)
124         {
125                 *Dest = Fill;
126                 Dest++;
127                 Count--;
128         }
129 }
130
131
132 /*
133  * @implemented
134  */
135 VOID
136 STDCALL
137 RtlMoveMemory (
138         PVOID           Destination,
139         CONST VOID      * Source,
140         ULONG           Length
141         )
142 {
143         memmove (
144                 Destination,
145                 Source,
146                 Length
147                 );
148 }
149
150
151 /*
152  * @implemented
153  */
154 VOID
155 STDCALL
156 RtlZeroMemory (
157         PVOID   Destination,
158         ULONG   Length
159         )
160 {
161         RtlFillMemory (
162                 Destination,
163                 Length,
164                 0
165                 );
166 }
167
168 /* EOF */