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