ReactOS
0.4.16-dev-747-gbc52d5f
genlist.c
Go to the documentation of this file.
1
/*
2
* PROJECT: ReactOS Setup Library
3
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4
* PURPOSE: Generic list functions
5
* COPYRIGHT: Copyright 2008-2018 Christoph von Wittich <christoph at reactos.org>
6
*/
7
8
/* INCLUDES *****************************************************************/
9
10
#include "precomp.h"
11
12
#include "
genlist.h
"
13
14
#define NDEBUG
15
#include <debug.h>
16
17
/* FUNCTIONS ****************************************************************/
18
19
PGENERIC_LIST
20
NTAPI
21
CreateGenericList
(
VOID
)
22
{
23
PGENERIC_LIST
List
;
24
25
List
=
RtlAllocateHeap
(
ProcessHeap
, 0,
sizeof
(
GENERIC_LIST
));
26
if
(
List
==
NULL
)
27
return
NULL
;
28
29
InitializeListHead
(&
List
->ListHead);
30
List
->NumOfEntries = 0;
31
List
->CurrentEntry =
NULL
;
32
33
return
List
;
34
}
35
36
VOID
37
NTAPI
38
DestroyGenericList
(
39
IN
OUT
PGENERIC_LIST
List
,
40
IN
BOOLEAN
FreeData)
41
{
42
PGENERIC_LIST_ENTRY
ListEntry;
43
PLIST_ENTRY
Entry
;
44
45
/* Release list entries */
46
while
(!
IsListEmpty
(&
List
->ListHead))
47
{
48
Entry
=
RemoveHeadList
(&
List
->ListHead);
49
ListEntry =
CONTAINING_RECORD
(
Entry
,
GENERIC_LIST_ENTRY
,
Entry
);
50
51
/* Release user data */
52
if
(FreeData && ListEntry->
Data
!=
NULL
)
53
RtlFreeHeap
(
ProcessHeap
, 0, ListEntry->
Data
);
54
55
/* Release list entry */
56
RtlFreeHeap
(
ProcessHeap
, 0, ListEntry);
57
}
58
59
/* Release list head */
60
RtlFreeHeap
(
ProcessHeap
, 0,
List
);
61
}
62
63
BOOLEAN
64
NTAPI
65
AppendGenericListEntry
(
66
IN
OUT
PGENERIC_LIST
List
,
67
IN
PVOID
Data
,
68
IN
BOOLEAN
Current)
69
{
70
PGENERIC_LIST_ENTRY
Entry
;
71
72
Entry
=
RtlAllocateHeap
(
ProcessHeap
, 0,
sizeof
(
GENERIC_LIST_ENTRY
));
73
if
(
Entry
==
NULL
)
74
return
FALSE
;
75
76
Entry
->List =
List
;
77
Entry
->Data =
Data
;
78
Entry
->UiData = 0;
79
80
InsertTailList
(&
List
->ListHead, &
Entry
->
Entry
);
81
++
List
->NumOfEntries;
82
83
if
(Current ||
List
->CurrentEntry ==
NULL
)
84
List
->CurrentEntry =
Entry
;
85
86
return
TRUE
;
87
}
88
89
VOID
90
NTAPI
91
SetCurrentListEntry
(
92
IN
PGENERIC_LIST
List
,
93
IN
PGENERIC_LIST_ENTRY
Entry
)
94
{
95
if
(!
Entry
|| (
Entry
->List !=
List
))
96
return
;
97
List
->CurrentEntry =
Entry
;
98
}
99
100
PGENERIC_LIST_ENTRY
101
NTAPI
102
GetCurrentListEntry
(
103
IN
PGENERIC_LIST
List
)
104
{
105
return
List
->CurrentEntry;
106
}
107
108
PGENERIC_LIST_ENTRY
109
NTAPI
110
GetFirstListEntry
(
111
IN
PGENERIC_LIST
List
)
112
{
113
if
(
IsListEmpty
(&
List
->ListHead))
114
return
NULL
;
115
116
return
CONTAINING_RECORD
(
List
->ListHead.Flink,
GENERIC_LIST_ENTRY
,
Entry
);
117
}
118
119
PGENERIC_LIST_ENTRY
120
NTAPI
121
GetNextListEntry
(
122
IN
PGENERIC_LIST_ENTRY
Entry
)
123
{
124
PLIST_ENTRY
Next
=
Entry
->
Entry
.Flink;
125
126
if
(
Next
== &
Entry
->List->ListHead)
127
return
NULL
;
128
129
return
CONTAINING_RECORD
(
Next
,
GENERIC_LIST_ENTRY
,
Entry
);
130
}
131
132
PVOID
133
NTAPI
134
GetListEntryData
(
135
IN
PGENERIC_LIST_ENTRY
Entry
)
136
{
137
return
Entry
->Data;
138
}
139
140
ULONG_PTR
141
GetListEntryUiData
(
142
IN
PGENERIC_LIST_ENTRY
Entry
)
143
{
144
return
Entry
->UiData;
145
}
146
147
ULONG
148
NTAPI
149
GetNumberOfListEntries
(
150
IN
PGENERIC_LIST
List
)
151
{
152
return
List
->NumOfEntries;
153
}
154
155
/* EOF */
BOOLEAN
unsigned char BOOLEAN
Definition:
ProcessorBind.h:185
ProcessHeap
HANDLE ProcessHeap
Definition:
servman.c:15
RtlAllocateHeap
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition:
heap.c:616
RtlFreeHeap
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition:
heap.c:634
NULL
#define NULL
Definition:
types.h:112
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
InsertTailList
#define InsertTailList(ListHead, Entry)
Definition:
env_spec_w32.h:1003
IsListEmpty
#define IsListEmpty(ListHead)
Definition:
env_spec_w32.h:954
RemoveHeadList
#define RemoveHeadList(ListHead)
Definition:
env_spec_w32.h:964
InitializeListHead
#define InitializeListHead(ListHead)
Definition:
env_spec_w32.h:944
void
Definition:
nsiface.idl:2307
GetNumberOfListEntries
ULONG NTAPI GetNumberOfListEntries(IN PGENERIC_LIST List)
Definition:
genlist.c:149
SetCurrentListEntry
VOID NTAPI SetCurrentListEntry(IN PGENERIC_LIST List, IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:91
DestroyGenericList
VOID NTAPI DestroyGenericList(IN OUT PGENERIC_LIST List, IN BOOLEAN FreeData)
Definition:
genlist.c:38
GetListEntryUiData
ULONG_PTR GetListEntryUiData(IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:141
CreateGenericList
PGENERIC_LIST NTAPI CreateGenericList(VOID)
Definition:
genlist.c:21
AppendGenericListEntry
BOOLEAN NTAPI AppendGenericListEntry(IN OUT PGENERIC_LIST List, IN PVOID Data, IN BOOLEAN Current)
Definition:
genlist.c:65
GetFirstListEntry
PGENERIC_LIST_ENTRY NTAPI GetFirstListEntry(IN PGENERIC_LIST List)
Definition:
genlist.c:110
GetNextListEntry
PGENERIC_LIST_ENTRY NTAPI GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:121
GetCurrentListEntry
PGENERIC_LIST_ENTRY NTAPI GetCurrentListEntry(IN PGENERIC_LIST List)
Definition:
genlist.c:102
GetListEntryData
PVOID NTAPI GetListEntryData(IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:134
Next
STDMETHOD() Next(THIS_ ULONG celt, IAssociationElement *pElement, ULONG *pceltFetched) PURE
Data
Definition:
sort_test.cpp:77
Entry
base of all file and directory entries
Definition:
entries.h:83
Entry::Entry
Entry(ENTRY_TYPE etype)
Definition:
entries.cpp:35
_GENERIC_LIST_ENTRY
Definition:
genlist.h:11
_GENERIC_LIST_ENTRY::Data
PVOID Data
Definition:
genlist.h:14
_GENERIC_LIST
Definition:
genlist.h:19
_LIST_ENTRY
Definition:
typedefs.h:120
NTAPI
#define NTAPI
Definition:
typedefs.h:36
ULONG_PTR
uint32_t ULONG_PTR
Definition:
typedefs.h:65
IN
#define IN
Definition:
typedefs.h:39
CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field)
Definition:
typedefs.h:260
ULONG
uint32_t ULONG
Definition:
typedefs.h:59
OUT
#define OUT
Definition:
typedefs.h:40
genlist.h
List
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition:
wdfresource.h:550
base
setup
lib
utils
genlist.c
Generated on Fri Feb 14 2025 06:02:37 for ReactOS by
1.9.6