8f1e413f138b6b0b38ce8a58d971c0c1ce98da1b
[reactos.git] / reactos / lib / rtl / mem.c
1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS system libraries
3 * FILE: lib/rtl/mem.c
4 * PURPOSE: Memory functions
5 * PROGRAMMER: David Welch (welch@mcmail.com)
6 */
7
8 /* INCLUDES *****************************************************************/
9
10 #include <rtl.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15
16 /* FUNCTIONS *****************************************************************/
17
18 /******************************************************************************
19 * RtlCompareMemory [NTDLL.@]
20 *
21 * Compare one block of memory with another
22 *
23 * PARAMS
24 * Source1 [I] Source block
25 * Source2 [I] Block to compare to Source1
26 * Length [I] Number of bytes to fill
27 *
28 * RETURNS
29 * The length of the first byte at which Source1 and Source2 differ, or Length
30 * if they are the same.
31 *
32 * @implemented
33 */
34 SIZE_T NTAPI
35 RtlCompareMemory(IN const VOID *Source1,
36 IN const VOID *Source2,
37 IN SIZE_T Length)
38 {
39 SIZE_T i;
40 for(i=0; (i<Length) && (((PUCHAR)Source1)[i]==((PUCHAR)Source2)[i]); i++)
41 ;
42 return i;
43 }
44
45
46 /*
47 * @implemented
48 */
49 SIZE_T
50 NTAPI
51 RtlCompareMemoryUlong (
52 PVOID Source,
53 SIZE_T Length,
54 ULONG Value
55 )
56 /*
57 * FUNCTION: Compares a block of ULONGs with an ULONG and returns the number of equal bytes
58 * ARGUMENTS:
59 * Source = Block to compare
60 * Length = Number of bytes to compare
61 * Value = Value to compare
62 * RETURNS: Number of equal bytes
63 */
64 {
65 PULONG ptr = (PULONG)Source;
66 ULONG_PTR len = Length / sizeof(ULONG);
67 ULONG_PTR i;
68
69 for (i = 0; i < len; i++)
70 {
71 if (*ptr != Value)
72 break;
73 ptr++;
74 }
75
76 return (SIZE_T)((PCHAR)ptr - (PCHAR)Source);
77 }
78
79
80 #undef RtlFillMemory
81 /*
82 * @implemented
83 */
84 VOID
85 NTAPI
86 RtlFillMemory (
87 PVOID Destination,
88 ULONG Length,
89 UCHAR Fill
90 )
91 {
92 memset(Destination, Fill, Length);
93 }
94
95
96
97 /*
98 * @implemented
99 */
100 VOID
101 NTAPI
102 RtlFillMemoryUlong (
103 PVOID Destination,
104 ULONG Length,
105 ULONG Fill
106 )
107 {
108 PULONG Dest = Destination;
109 ULONG Count = Length / sizeof(ULONG);
110
111 while (Count > 0)
112 {
113 *Dest = Fill;
114 Dest++;
115 Count--;
116 }
117 }
118
119
120 #undef RtlMoveMemory
121 /*
122 * @implemented
123 */
124 VOID
125 NTAPI
126 RtlMoveMemory (
127 PVOID Destination,
128 CONST VOID * Source,
129 ULONG Length
130 )
131 {
132 memmove (
133 Destination,
134 Source,
135 Length
136 );
137 }
138
139 /*
140 * @implemented
141 */
142 VOID
143 FASTCALL
144 RtlPrefetchMemoryNonTemporal(
145 IN PVOID Source,
146 IN SIZE_T Length
147 )
148 {
149 /* By nature of prefetch, this is non-portable. */
150 (void)Source;
151 (void)Length;
152 }
153
154
155 #undef RtlZeroMemory
156 /*
157 * @implemented
158 */
159 VOID
160 NTAPI
161 RtlZeroMemory (
162 PVOID Destination,
163 ULONG Length
164 )
165 {
166 RtlFillMemory (
167 Destination,
168 Length,
169 0
170 );
171 }
172
173 /* EOF */