ReactOS 0.4.15-dev-7953-g1f49173
pnputil.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for pnputil.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI PnpFreeUnicodeStringList (IN PUNICODE_STRING UnicodeStringList, IN ULONG StringCount)
 
NTSTATUS NTAPI PnpRegMultiSzToUnicodeStrings (IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation, OUT PUNICODE_STRING *UnicodeStringList, OUT PULONG UnicodeStringCount)
 
BOOLEAN NTAPI PnpRegSzToString (IN PWCHAR RegSzData, IN ULONG RegSzLength, OUT PUSHORT StringLength OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file pnputil.c.

Function Documentation

◆ PnpFreeUnicodeStringList()

VOID NTAPI PnpFreeUnicodeStringList ( IN PUNICODE_STRING  UnicodeStringList,
IN ULONG  StringCount 
)

Definition at line 21 of file pnputil.c.

23{
24 ULONG i;
25
26 /* Go through the list */
27 if (UnicodeStringList)
28 {
29 /* Go through each string */
30 for (i = 0; i < StringCount; i++)
31 {
32 /* Check if it exists */
33 if (UnicodeStringList[i].Buffer)
34 {
35 /* Free it */
36 ExFreePool(UnicodeStringList[i].Buffer);
37 }
38 }
39
40 /* Free the whole list */
41 ExFreePool(UnicodeStringList);
42 }
43}
Definition: bufpool.h:45
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t ULONG
Definition: typedefs.h:59

Referenced by PnpRegMultiSzToUnicodeStrings().

◆ PnpRegMultiSzToUnicodeStrings()

NTSTATUS NTAPI PnpRegMultiSzToUnicodeStrings ( IN PKEY_VALUE_FULL_INFORMATION  KeyValueInformation,
OUT PUNICODE_STRING UnicodeStringList,
OUT PULONG  UnicodeStringCount 
)

Definition at line 47 of file pnputil.c.

50{
51 PWCHAR p, pp, ps;
52 ULONG i = 0;
53 SIZE_T n;
54 ULONG Count = 0;
55
56 /* Validate the key information */
57 if (KeyValueInformation->Type != REG_MULTI_SZ) return STATUS_INVALID_PARAMETER;
58
59 /* Set the pointers */
60 p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
61 KeyValueInformation->DataOffset);
62 pp = (PWCHAR)((ULONG_PTR)p + KeyValueInformation->DataLength);
63
64 /* Loop the data */
65 while (p != pp)
66 {
67 /* If we find a NULL, that means one string is done */
68 if (!*p)
69 {
70 /* Add to our string count */
71 Count++;
72
73 /* Check for a double-NULL, which means we're done */
74 if (((p + 1) == pp) || !(*(p + 1))) break;
75 }
76
77 /* Go to the next character */
78 p++;
79 }
80
81 /* If we looped the whole list over, we missed increment a string, do it */
82 if (p == pp) Count++;
83
84 /* Allocate the list now that we know how big it is */
85 *UnicodeStringList = ExAllocatePoolWithTag(PagedPool,
86 sizeof(UNICODE_STRING) * Count,
87 'sUpP');
88 if (!(*UnicodeStringList)) return STATUS_INSUFFICIENT_RESOURCES;
89
90 /* Set pointers for second loop */
91 ps = p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
92 KeyValueInformation->DataOffset);
93
94 /* Loop again, to do the copy this time */
95 while (p != pp)
96 {
97 /* If we find a NULL, that means one string is done */
98 if (!*p)
99 {
100 /* Check how long this string is */
101 n = (ULONG_PTR)p - (ULONG_PTR)ps + sizeof(UNICODE_NULL);
102
103 /* Allocate the buffer */
104 (*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
105 n,
106 'sUpP');
107 if (!(*UnicodeStringList)[i].Buffer)
108 {
109 /* Back out of everything */
110 PnpFreeUnicodeStringList(*UnicodeStringList, i);
112 }
113
114 /* Copy the string into the buffer */
115 RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
116
117 /* Set the lengths */
118 (*UnicodeStringList)[i].MaximumLength = (USHORT)n;
119 (*UnicodeStringList)[i].Length = (USHORT)(n - sizeof(UNICODE_NULL));
120
121 /* One more entry done */
122 i++;
123
124 /* Check for a double-NULL, which means we're done */
125 if (((p + 1) == pp) || !(*(p + 1))) break;
126
127 /* New string */
128 ps = p + 1;
129 }
130
131 /* New string */
132 p++;
133 }
134
135 /* Check if we've reached the last string */
136 if (p == pp)
137 {
138 /* Calculate the string length */
139 n = (ULONG_PTR)p - (ULONG_PTR)ps;
140
141 /* Allocate the buffer for it */
142 (*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
143 n +
144 sizeof(UNICODE_NULL),
145 'sUpP');
146 if (!(*UnicodeStringList)[i].Buffer)
147 {
148 /* Back out of everything */
149 PnpFreeUnicodeStringList(*UnicodeStringList, i);
151 }
152
153 /* Make sure there's an actual string here */
154 if (n) RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
155
156 /* Null-terminate the string ourselves */
157 (*UnicodeStringList)[i].Buffer[n / sizeof(WCHAR)] = UNICODE_NULL;
158
159 /* Set the lengths */
160 (*UnicodeStringList)[i].Length = (USHORT)n;
161 (*UnicodeStringList)[i].MaximumLength = (USHORT)(n + sizeof(UNICODE_NULL));
162 }
163
164 /* And we're done */
165 *UnicodeStringCount = Count;
166 return STATUS_SUCCESS;
167}
#define ULONG_PTR
Definition: config.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
int Count
Definition: noreturn.cpp:7
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define UNICODE_NULL
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI PnpFreeUnicodeStringList(IN PUNICODE_STRING UnicodeStringList, IN ULONG StringCount)
Definition: pnputil.c:21
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PiInitCacheGroupInformation().

◆ PnpRegSzToString()

BOOLEAN NTAPI PnpRegSzToString ( IN PWCHAR  RegSzData,
IN ULONG  RegSzLength,
OUT PUSHORT StringLength  OPTIONAL 
)

Definition at line 171 of file pnputil.c.

174{
175 PWCHAR p, pp;
176
177 /* Find the end */
178 pp = RegSzData + RegSzLength / sizeof(WCHAR);
179 for (p = RegSzData; p < pp; p++)
180 {
181 if (!*p)
182 {
183 break;
184 }
185 }
186
187 /* Return the length. Truncation can happen but is of no consequence. */
188 if (StringLength)
189 {
190 *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR);
191 }
192 return TRUE;
193}
#define TRUE
Definition: types.h:120

Referenced by PipGetDriverTagPriority(), and PpInitGetGroupOrderIndex().