393f2d68344173756443a4540d2760acbe598f78
[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 ULONG
46 STDCALL
47 RtlCompareMemoryUlong (
48         PVOID   Source,
49         ULONG   Length,
50         ULONG   Value
51         )
52 /*
53  * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
54  * ARGUMENTS:
55  *      Source = Block to compare
56  *      Length = Number of bytes to compare
57  *      Value = Value to compare
58  * RETURNS: Number of equal bytes
59  */
60 {
61         PULONG ptr = (PULONG)Source;
62         ULONG  len = Length / sizeof(ULONG);
63         int i;
64
65         for (i = 0; i < len; i++)
66         {
67                 if (*ptr != Value)
68                         break;
69                 ptr++;
70         }
71
72         return (ULONG)((PCHAR)ptr - (PCHAR)Source);
73 }
74
75 #if 0
76 VOID RtlCopyBytes(PVOID Destination,
77                   CONST VOID* Source,
78                   ULONG Length)
79 {
80    RtlCopyMemory(Destination,Source,Length);
81 }
82
83 VOID RtlCopyMemory(VOID* Destination, CONST VOID* Source, ULONG Length)
84 {
85    DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
86           Destination,Source,Length);
87    memcpy(Destination,Source,Length);
88    DPRINT("*Destination %x\n",*(PULONG)Destination);
89 }
90 #endif
91
92 VOID 
93 STDCALL
94 RtlFillMemory (
95         PVOID   Destination,
96         ULONG   Length,
97         UCHAR   Fill
98         )
99 {
100         memset(Destination, Fill, Length);
101 }
102
103 VOID
104 STDCALL
105 RtlFillMemoryUlong (
106         PVOID   Destination,
107         ULONG   Length,
108         ULONG   Fill
109         )
110 {
111         PULONG Dest  = Destination;
112         ULONG  Count = Length / sizeof(ULONG);
113
114         while (Count > 0)
115         {
116                 *Dest = Fill;
117                 Dest++;
118                 Count--;
119         }
120 }
121
122
123 VOID
124 STDCALL
125 RtlMoveMemory (
126         PVOID           Destination,
127         CONST VOID      * Source,
128         ULONG           Length
129         )
130 {
131         memmove (
132                 Destination,
133                 Source,
134                 Length
135                 );
136 }
137
138
139 VOID
140 STDCALL
141 RtlZeroMemory (
142         PVOID   Destination,
143         ULONG   Length
144         )
145 {
146         RtlFillMemory (
147                 Destination,
148                 Length,
149                 0
150                 );
151 }
152
153
154 /* EOF */