ReactOS 0.4.15-dev-5666-gc548b97
mswhelper.h File Reference
#include <ws2spi.h>
Include dependency graph for mswhelper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MSW_BUFFER
 

Typedefs

typedef struct MSW_BUFFERPMSW_BUFFER
 

Functions

void mswBufferInit (_Out_ PMSW_BUFFER mswBuf, _In_ BYTE *buffer, _In_ DWORD bufferSize)
 
BOOL mswBufferCheck (_Inout_ PMSW_BUFFER mswBuf, _In_ DWORD count)
 
BOOL mswBufferIncUsed (_Inout_ PMSW_BUFFER mswBuf, _In_ DWORD count)
 
BYTEmswBufferEndPtr (_Inout_ PMSW_BUFFER mswBuf)
 
BOOL mswBufferAppend (_Inout_ PMSW_BUFFER mswBuf, _In_ void *dataToAppend, _In_ DWORD dataSize)
 
BOOL mswBufferAppendStrA (_Inout_ PMSW_BUFFER mswBuf, _In_ char *str)
 
BOOL mswBufferAppendStrW (_Inout_ PMSW_BUFFER mswBuf, _In_ WCHAR *str)
 
BOOL mswBufferAppendPtr (_Inout_ PMSW_BUFFER mswBuf, _In_ void *ptr)
 
BOOL mswBufferAppendLst (_Inout_ PMSW_BUFFER mswBuf, _In_ void **lst, _In_ DWORD itemByteLength, _In_opt_ int deltaofs)
 
BOOL mswBufferAppendStrLstA (_Inout_ PMSW_BUFFER mswBuf, _In_ void **lst, _In_opt_ int ptrofs)
 
BOOL mswBufferAppendBlob_Hostent (_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ char **hostAliasesA, _In_ char *hostnameA, _In_ DWORD ip4addr)
 
BOOL mswBufferAppendBlob_Servent (_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ char *serviceNameA, _In_ char **serviceAliasesA, _In_ char *protocolNameA, _In_ WORD port)
 
BOOL mswBufferAppendAddr_AddrInfoW (_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ DWORD ip4addr)
 
WCHARStrA2WHeapAlloc (_In_opt_ HANDLE hHeap, _In_ char *aStr)
 
charStrW2AHeapAlloc (_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
 
WCHARStrCpyHeapAllocW (_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
 
charStrCpyHeapAllocA (_In_opt_ HANDLE hHeap, _In_ char *aStr)
 
char ** StrAryCpyHeapAllocA (_In_opt_ HANDLE hHeap, _In_ char **aStrAry)
 
char ** StrAryCpyHeapAllocWToA (_In_opt_ HANDLE hHeap, _In_ WCHAR **aStrAry)
 

Typedef Documentation

◆ PMSW_BUFFER

Function Documentation

◆ mswBufferAppend()

BOOL mswBufferAppend ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ void dataToAppend,
_In_ DWORD  dataSize 
)

Definition at line 57 of file mswhelper.c.

60{
61 if (!mswBufferCheck(mswBuf, dataSize))
62 return FALSE;
63
64 RtlCopyMemory(mswBuf->bufendptr, dataToAppend, dataSize);
65 mswBuf->bytesUsed += dataSize;
66 mswBuf->bufendptr += dataSize;
67
68 return TRUE;
69}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLenum GLsizei dataSize
Definition: glext.h:11123
BOOL mswBufferCheck(_Inout_ PMSW_BUFFER mswBuf, _In_ DWORD count)
Definition: mswhelper.c:28
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by mswBufferAppendLst(), mswBufferAppendPtr(), mswBufferAppendStrA(), and mswBufferAppendStrW().

◆ mswBufferAppendAddr_AddrInfoW()

BOOL mswBufferAppendAddr_AddrInfoW ( _Inout_ PMSW_BUFFER  mswBuf,
_Inout_ LPWSAQUERYSETW  lpRes,
_In_ DWORD  ip4addr 
)

Definition at line 352 of file mswhelper.c.

355{
356 LPCSADDR_INFO paddrinfo;
358
359 lpRes->dwNumberOfCsAddrs = 1;
360 lpRes->lpcsaBuffer = (LPCSADDR_INFO)mswBufferEndPtr(mswBuf);
361
362 paddrinfo = lpRes->lpcsaBuffer;
363
364 if (!mswBufferIncUsed(mswBuf, sizeof(*paddrinfo)))
365 return FALSE;
366
367 paddrinfo->LocalAddr.lpSockaddr = (LPSOCKADDR)mswBufferEndPtr(mswBuf);
368
369 if (!mswBufferIncUsed(mswBuf, sizeof(*paddrinfo->LocalAddr.lpSockaddr)))
370 return FALSE;
371
372 paddrinfo->RemoteAddr.lpSockaddr = (LPSOCKADDR)mswBufferEndPtr(mswBuf);
373
374 if (!mswBufferIncUsed(mswBuf, sizeof(*paddrinfo->RemoteAddr.lpSockaddr)))
375 return FALSE;
376
377 paddrinfo->iSocketType = SOCK_DGRAM;
378 paddrinfo->iProtocol = IPPROTO_UDP;
379
381 paddrinfo->LocalAddr.iSockaddrLength = sizeof(*psa);
382 psa->sin_family = AF_INET;
383 psa->sin_port = 0;
384 psa->sin_addr.s_addr = 0;
385 RtlZeroMemory(psa->sin_zero, sizeof(psa->sin_zero));
386
388 paddrinfo->RemoteAddr.iSockaddrLength = sizeof(*psa);
389 psa->sin_family = AF_INET;
390 psa->sin_port = 0;
391 psa->sin_addr.s_addr = ip4addr;
392 RtlZeroMemory(psa->sin_zero, sizeof(psa->sin_zero));
393
394 return TRUE;
395}
#define IPPROTO_UDP
Definition: ip.h:197
#define AF_INET
Definition: tcpip.h:117
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
BOOL mswBufferIncUsed(_Inout_ PMSW_BUFFER mswBuf, _In_ DWORD count)
Definition: mswhelper.c:39
BYTE * mswBufferEndPtr(_Inout_ PMSW_BUFFER mswBuf)
Definition: mswhelper.c:51
INT iProtocol
Definition: ws2def.h:394
SOCKET_ADDRESS RemoteAddr
Definition: ws2def.h:392
INT iSocketType
Definition: ws2def.h:393
SOCKET_ADDRESS LocalAddr
Definition: ws2def.h:391
LPSOCKADDR lpSockaddr
Definition: ws2def.h:375
INT iSockaddrLength
Definition: ws2def.h:376
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct sockaddr_in * LPSOCKADDR_IN
Definition: winsock.h:489
#define SOCK_DGRAM
Definition: winsock.h:336
struct sockaddr * LPSOCKADDR
Definition: winsock.h:486
struct _CSADDR_INFO * LPCSADDR_INFO

Referenced by NSP_LookupServiceNextW().

◆ mswBufferAppendBlob_Hostent()

BOOL mswBufferAppendBlob_Hostent ( _Inout_ PMSW_BUFFER  mswBuf,
_Inout_ LPWSAQUERYSETW  lpRes,
_In_ char **  hostAliasesA,
_In_ char hostnameA,
_In_ DWORD  ip4addr 
)

Definition at line 227 of file mswhelper.c.

232{
233 PHOSTENT phe;
234 void* lst[2];
235 BYTE* bytesOfs;
236
237 /* blob */
238 lpRes->lpBlob = (LPBLOB)mswBufferEndPtr(mswBuf);
239
240 if (!mswBufferIncUsed(mswBuf, sizeof(*lpRes->lpBlob)))
241 return FALSE;
242
243 /* cbSize will be set later */
244 lpRes->lpBlob->cbSize = 0;
245 lpRes->lpBlob->pBlobData = mswBufferEndPtr(mswBuf);
246
247 /* hostent */
248 phe = (PHOSTENT)lpRes->lpBlob->pBlobData;
249 bytesOfs = mswBufferEndPtr(mswBuf);
250
251 if (!mswBufferIncUsed(mswBuf, sizeof(*phe)))
252 return FALSE;
253
254 phe->h_addrtype = AF_INET;
255 phe->h_length = 4; /* 4 Byte (IPv4) */
256
257 /* aliases */
258 phe->h_aliases = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs);
259
260 if (hostAliasesA)
261 {
262 if (!mswBufferAppendStrLstA(mswBuf,
263 (void**)hostAliasesA,
264 -(LONG_PTR)bytesOfs))
265 return FALSE;
266 }
267 else
268 {
269 if (!mswBufferAppendPtr(mswBuf, NULL))
270 return FALSE;
271 }
272
273 /* addr_list */
274 RtlZeroMemory(lst, sizeof(lst));
275
276 lst[0] = (void*)&ip4addr;
277
278 phe->h_addr_list = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs);
279
280 if (!mswBufferAppendLst(mswBuf, lst, 4, -(LONG_PTR)bytesOfs))
281 return FALSE;
282
283 /* name */
284 phe->h_name = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs);
285
286 if (!mswBufferAppendStrA(mswBuf, hostnameA))
287 return FALSE;
288
289 lpRes->lpBlob->cbSize = (DWORD)(mswBufferEndPtr(mswBuf) - bytesOfs);
290 return mswBuf->bufok;
291}
#define NULL
Definition: types.h:112
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
BOOL mswBufferAppendLst(_Inout_ PMSW_BUFFER mswBuf, _In_ void **lst, _In_ DWORD itemByteLength, _In_opt_ int ptrofs)
Definition: mswhelper.c:104
BOOL mswBufferAppendStrA(_Inout_ PMSW_BUFFER mswBuf, _In_ char *str)
Definition: mswhelper.c:71
BOOL mswBufferAppendPtr(_Inout_ PMSW_BUFFER mswBuf, _In_ void *ptr)
Definition: mswhelper.c:86
BOOL mswBufferAppendStrLstA(_Inout_ PMSW_BUFFER mswBuf, _In_ void **lst, _In_opt_ int ptrofs)
Definition: mswhelper.c:160
struct _BLOB * LPBLOB
#define DWORD
Definition: nt_native.h:44
char * h_name
Definition: winsock.h:134
short h_length
Definition: winsock.h:137
char ** h_aliases
Definition: winsock.h:135
short h_addrtype
Definition: winsock.h:136
char ** h_addr_list
Definition: winsock.h:138
#define LONG_PTR
Definition: treelist.c:79
struct hostent * PHOSTENT
Definition: winsock.h:497
unsigned char BYTE
Definition: xxhash.c:193

Referenced by NSP_LookupServiceNextW().

◆ mswBufferAppendBlob_Servent()

BOOL mswBufferAppendBlob_Servent ( _Inout_ PMSW_BUFFER  mswBuf,
_Inout_ LPWSAQUERYSETW  lpRes,
_In_ char serviceNameA,
_In_ char **  serviceAliasesA,
_In_ char protocolNameA,
_In_ WORD  port 
)

Definition at line 294 of file mswhelper.c.

300{
301 PSERVENT pse;
302 BYTE* bytesOfs;
303
304 /* blob */
305 lpRes->lpBlob = (LPBLOB)mswBufferEndPtr(mswBuf);
306
307 if (!mswBufferIncUsed(mswBuf, sizeof(*lpRes->lpBlob)))
308 return FALSE;
309
310 lpRes->lpBlob->cbSize = 0;//later
311 lpRes->lpBlob->pBlobData = mswBufferEndPtr(mswBuf);
312
313 /* servent */
314 pse = (LPSERVENT)lpRes->lpBlob->pBlobData;
315 bytesOfs = mswBufferEndPtr(mswBuf);
316
317 if (!mswBufferIncUsed(mswBuf, sizeof(*pse)))
318 return FALSE;
319
320 pse->s_aliases = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs);
321
322 if (serviceAliasesA)
323 {
324 if (!mswBufferAppendStrLstA(mswBuf,
325 (void**)serviceAliasesA,
326 -(LONG_PTR)bytesOfs))
327 return FALSE;
328 }
329 else
330 {
331 if (!mswBufferAppendPtr(mswBuf, NULL))
332 return FALSE;
333 }
334
335 pse->s_name = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs);
336
337 if (!mswBufferAppendStrA(mswBuf, serviceNameA))
338 return FALSE;
339
340 pse->s_port = htons(port);
341
342 pse->s_proto = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs);
343
344 if (!mswBufferAppendStrA(mswBuf, protocolNameA))
345 return FALSE;
346
347 lpRes->lpBlob->cbSize = (DWORD)(mswBufferEndPtr(mswBuf) - bytesOfs);
348 return mswBuf->bufok;
349}
USHORT port
Definition: uri.c:228
#define htons(x)
Definition: module.h:213
char * s_name
Definition: winsock.h:159
short s_port
Definition: winsock.h:165
char * s_proto
Definition: winsock.h:166
char ** s_aliases
Definition: winsock.h:160
struct servent * LPSERVENT
Definition: winsock.h:501

Referenced by NSP_LookupServiceNextW().

◆ mswBufferAppendLst()

BOOL mswBufferAppendLst ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ void **  lst,
_In_ DWORD  itemByteLength,
_In_opt_ int  deltaofs 
)

Definition at line 104 of file mswhelper.c.

108{
109 DWORD lstItemCount;
110 DWORD lstByteSize;
111 DWORD_PTR lstDataPos;
112 DWORD i1;
113 UINT_PTR *ptrSrcLstPos;
114
115 /* calculate size of list */
116 ptrSrcLstPos = (UINT_PTR*)lst;
117 lstItemCount = 0;
118 while (*ptrSrcLstPos != (UINT_PTR)NULL)
119 {
120 lstItemCount++;
121 ptrSrcLstPos++;
122 }
123
124 lstByteSize = ((lstItemCount + 1) * sizeof(UINT_PTR)) + /* item-pointer + null-ptr (for end) */
125 (lstItemCount * itemByteLength); /* item-data */
126
127 if (mswBuf->bytesUsed + lstByteSize > mswBuf->bytesMax)
128 return FALSE;
129
130 /* calculate position for the data of the first item */
131 lstDataPos = ((lstItemCount + 1) * sizeof(UINT_PTR)) +
132 (DWORD_PTR)mswBufferEndPtr(mswBuf);
133 /* add ptrofs */
134 lstDataPos += ptrofs;
135
136 /* write array of Pointer to data */
137 for (i1 = 0; i1 < lstItemCount; i1++)
138 {
139 if (!mswBufferAppendPtr(mswBuf, (void*)lstDataPos))
140 return FALSE;
141
142 lstDataPos += sizeof(UINT_PTR);
143 }
144
145 /* end of list */
146 if (!mswBufferAppendPtr(mswBuf, NULL))
147 return FALSE;
148
149 /* write data */
150 ptrSrcLstPos = (UINT_PTR*)lst;
151 for (i1 = 0; i1 < lstItemCount; i1++)
152 {
153 mswBufferAppend(mswBuf, *(BYTE**)ptrSrcLstPos, itemByteLength);
154 ptrSrcLstPos++;
155 }
156 return mswBuf->bufok;
157}
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
BOOL mswBufferAppend(_Inout_ PMSW_BUFFER mswBuf, _In_ void *dataToAppend, _In_ DWORD dataSize)
Definition: mswhelper.c:57
uint32_t DWORD_PTR
Definition: typedefs.h:65

Referenced by mswBufferAppendBlob_Hostent().

◆ mswBufferAppendPtr()

BOOL mswBufferAppendPtr ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ void ptr 
)

Definition at line 86 of file mswhelper.c.

88{
89 return mswBufferAppend(mswBuf, &ptr, sizeof(ptr));
90}
static PVOID ptr
Definition: dispmode.c:27

Referenced by mswBufferAppendBlob_Hostent(), mswBufferAppendBlob_Servent(), mswBufferAppendLst(), and mswBufferAppendStrLstA().

◆ mswBufferAppendStrA()

BOOL mswBufferAppendStrA ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ char str 
)

Definition at line 71 of file mswhelper.c.

73{
74 return mswBufferAppend(mswBuf, str, strlen(str) + sizeof(char));
75}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
const WCHAR * str

Referenced by mswBufferAppendBlob_Hostent(), mswBufferAppendBlob_Servent(), and mswBufferAppendStrLstA().

◆ mswBufferAppendStrLstA()

BOOL mswBufferAppendStrLstA ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ void **  lst,
_In_opt_ int  ptrofs 
)

Definition at line 160 of file mswhelper.c.

163{
164 DWORD lstItemLen[MAX_ARRAY_SIZE];
165 DWORD lstItemCount;
166 DWORD lstByteSize;
167 DWORD_PTR lstDataPos;
168 DWORD lstDataSize;
169 DWORD i1;
170 UINT_PTR *ptrSrcLstPos;
171
172 /* calculate size of list */
173 ptrSrcLstPos = (UINT_PTR*)lst;
174 lstItemCount = 0;
175 lstDataSize = 0;
176
177 while (*ptrSrcLstPos != (UINT_PTR)NULL)
178 {
179 if (lstItemCount >= MAX_ARRAY_SIZE)
180 return FALSE;
181
182 i1 = strlen((char*)*ptrSrcLstPos) + sizeof(char);
183 lstItemLen[lstItemCount] = i1;
184 lstItemCount++;
185 lstDataSize += i1;
186 ptrSrcLstPos++;
187 }
188
189 lstByteSize = ((lstItemCount + 1) * sizeof(UINT_PTR)) + /* item-pointer + null-ptr (for end) */
190 lstDataSize; /* item-data */
191
192 if (mswBuf->bytesUsed + lstByteSize > mswBuf->bytesMax)
193 return FALSE;
194
195 /* calculate position for the data of the first item */
196 lstDataPos = ((lstItemCount + 1) * sizeof(UINT_PTR)) +
197 (DWORD_PTR)mswBufferEndPtr(mswBuf);
198
199 /* add ptrofs */
200 lstDataPos += ptrofs;
201
202 for (i1 = 0; i1 < lstItemCount; i1++)
203 {
204 if (!mswBufferAppendPtr(mswBuf, (void*)lstDataPos))
205 return FALSE;
206
207 lstDataPos += lstItemLen[i1];
208 }
209
210 /* end of list */
211 if (!mswBufferAppendPtr(mswBuf, NULL))
212 return FALSE;
213
214 /* write data */
215 ptrSrcLstPos = (UINT_PTR*)lst;
216 for (i1 = 0; i1 < lstItemCount; i1++)
217 {
218 if (!mswBufferAppendStrA(mswBuf, *(char**)ptrSrcLstPos))
219 return FALSE;
220
221 ptrSrcLstPos++;
222 }
223 return mswBuf->bufok;
224}
unsigned char
Definition: typeof.h:29
#define MAX_ARRAY_SIZE
Definition: mswhelper.c:12

Referenced by mswBufferAppendBlob_Hostent(), and mswBufferAppendBlob_Servent().

◆ mswBufferAppendStrW()

BOOL mswBufferAppendStrW ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ WCHAR str 
)

Definition at line 78 of file mswhelper.c.

80{
81 int bytelen = (wcslen(str) + 1) * sizeof(WCHAR);
82 return mswBufferAppend(mswBuf, str, bytelen);
83}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by NSP_LookupServiceNextW().

◆ mswBufferCheck()

BOOL mswBufferCheck ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ DWORD  count 
)

Definition at line 28 of file mswhelper.c.

30{
31 if (mswBuf->bytesUsed + count <= mswBuf->bytesMax)
32 return TRUE;
33
34 mswBuf->bufok = FALSE;
35 return FALSE;
36}

Referenced by mswBufferAppend(), and mswBufferIncUsed().

◆ mswBufferEndPtr()

BYTE * mswBufferEndPtr ( _Inout_ PMSW_BUFFER  mswBuf)

◆ mswBufferIncUsed()

BOOL mswBufferIncUsed ( _Inout_ PMSW_BUFFER  mswBuf,
_In_ DWORD  count 
)

Definition at line 39 of file mswhelper.c.

41{
42 if (!mswBufferCheck(mswBuf, count))
43 return FALSE;
44
45 mswBuf->bytesUsed += count;
46 mswBuf->bufendptr += count;
47 return TRUE;
48}
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by mswBufferAppendAddr_AddrInfoW(), mswBufferAppendBlob_Hostent(), mswBufferAppendBlob_Servent(), and NSP_LookupServiceNextW().

◆ mswBufferInit()

void mswBufferInit ( _Out_ PMSW_BUFFER  mswBuf,
_In_ BYTE buffer,
_In_ DWORD  bufferSize 
)

◆ StrA2WHeapAlloc()

WCHAR * StrA2WHeapAlloc ( _In_opt_ HANDLE  hHeap,
_In_ char aStr 
)

Definition at line 399 of file mswhelper.c.

401{
402 int aStrByteLen;
403 int wStrByteLen;
404 int charLen;
405 int ret;
406 WCHAR* wStr;
407
408 if (aStr == NULL)
409 return NULL;
410
411 charLen = strlen(aStr) + 1;
412
413 aStrByteLen = (charLen * sizeof(char));
414 wStrByteLen = (charLen * sizeof(WCHAR));
415
416 if (hHeap == 0)
417 hHeap = GetProcessHeap();
418
419 wStr = HeapAlloc(hHeap, 0, wStrByteLen);
420 if (wStr == NULL)
421 {
422 HeapFree(hHeap, 0, wStr);
423 return NULL;
424 }
425
427 0,
428 aStr,
429 aStrByteLen,
430 wStr,
431 charLen);
432
433 if (ret != charLen)
434 {
435 HeapFree(hHeap, 0, wStr);
436 return NULL;
437 }
438 return wStr;
439}
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
int ret

Referenced by NSP_GetServiceByNameHeapAllocW(), and NSP_LookupServiceBeginW().

◆ StrAryCpyHeapAllocA()

char ** StrAryCpyHeapAllocA ( _In_opt_ HANDLE  hHeap,
_In_ char **  aStrAry 
)

Definition at line 530 of file mswhelper.c.

532{
533 char** aSrcPtr;
534 char** aDstPtr;
535 char* aDstNextStr;
536 DWORD aStrByteLen[MAX_ARRAY_SIZE];
537 size_t bLen;
538 size_t bItmLen;
539 int aCount;
540 int i1;
541 char** resA;
542
543 if (hHeap == 0)
544 hHeap = GetProcessHeap();
545
546 /* Calculating size of array ... */
547 aSrcPtr = aStrAry;
548 bLen = 0;
549 aCount = 0;
550
551 while (*aSrcPtr != NULL)
552 {
553 if (aCount >= MAX_ARRAY_SIZE)
554 return NULL;
555
556 bItmLen = strlen(*aSrcPtr) + 1;
557 aStrByteLen[aCount] = bItmLen;
558
559 bLen += sizeof(*aSrcPtr) + bItmLen;
560
561 aSrcPtr++;
562 aCount++;
563 }
564
565 /* size for NULL-terminator */
566 bLen += sizeof(*aSrcPtr);
567
568 /* get memory */
569 resA = HeapAlloc(hHeap, 0, bLen);
570
571 /* copy data */
572 aSrcPtr = aStrAry;
573 aDstPtr = resA;
574
575 /* pos for the first string */
576 aDstNextStr = (char*)(resA + aCount + 1);
577 for (i1 = 0; i1 < aCount; i1++)
578 {
579 bItmLen = aStrByteLen[i1];
580
581 *aDstPtr = aDstNextStr;
582 RtlCopyMemory(*aDstPtr, *aSrcPtr, bItmLen);
583
584 aDstNextStr = (char*)((DWORD_PTR)aDstNextStr + (DWORD)bItmLen);
585 aDstPtr++;
586 aSrcPtr++;
587 }
588
589 /* terminate with NULL */
590 *aDstPtr = NULL;
591
592 return resA;
593}

Referenced by NSP_GetServiceByNameHeapAllocW().

◆ StrAryCpyHeapAllocWToA()

char ** StrAryCpyHeapAllocWToA ( _In_opt_ HANDLE  hHeap,
_In_ WCHAR **  aStrAry 
)

Definition at line 596 of file mswhelper.c.

598{
599 WCHAR** wSrcPtr;
600 char** aDstPtr;
601 char* aDstNextStr;
602 DWORD aStrByteLen[MAX_ARRAY_SIZE];
603 int bLen;
604 int bItmLen;
605 int aCount;
606 int i1;
607 char** resA;
608 int ret;
609 char* aStr;
610
611 if (hHeap == 0)
612 hHeap = GetProcessHeap();
613
614 /* Calculating size of array ... */
615 wSrcPtr = wStrAry;
616 bLen = 0;
617 aCount = 0;
618
619 while (*wSrcPtr != NULL)
620 {
621 if (aCount >= MAX_ARRAY_SIZE)
622 return NULL;
623
624 bItmLen = wcslen(*wSrcPtr) + 1;
625 aStrByteLen[aCount] = bItmLen;
626
627 bLen += sizeof(*wSrcPtr) + bItmLen;
628
629 wSrcPtr++;
630 aCount++;
631 }
632
633 /* size for NULL-terminator */
634 bLen += sizeof(*wSrcPtr);
635
636 /* get memory */
637 resA = HeapAlloc(hHeap, 0, bLen);
638
639 /* copy data */
640 wSrcPtr = wStrAry;
641 aDstPtr = resA;
642
643 /* pos for the first string */
644 aDstNextStr = (char*)(resA + aCount + 1);
645 for (i1 = 0; i1 < aCount; i1++)
646 {
647 bItmLen = aStrByteLen[i1];
648
649 *aDstPtr = aDstNextStr;
650
651 aStr = HeapAlloc(hHeap, 0, bItmLen);
652 if (aStr == NULL)
653 {
654 HeapFree(hHeap, 0, aStr);
655 return NULL;
656 }
657
659 0,
660 *wSrcPtr,
661 bItmLen,
662 aStr,
663 bItmLen,
664 NULL,
665 NULL);
666 if (ret != bItmLen)
667 {
668 HeapFree(hHeap, 0, aStr);
669 return NULL;
670 }
671 RtlCopyMemory(*aDstPtr, aStr, bItmLen);
672 HeapFree(hHeap, 0, aStr);
673
674 aDstNextStr = (char*)((DWORD_PTR)aDstNextStr + (DWORD)bItmLen);
675 aDstPtr++;
676 wSrcPtr++;
677 }
678
679 /* terminate with NULL */
680 *aDstPtr = NULL;
681
682 return resA;
683}
#define WideCharToMultiByte
Definition: compat.h:111

Referenced by NSP_GetHostByNameHeapAllocW().

◆ StrCpyHeapAllocA()

char * StrCpyHeapAllocA ( _In_opt_ HANDLE  hHeap,
_In_ char aStr 
)

Definition at line 507 of file mswhelper.c.

509{
510 size_t chLen;
511 size_t bLen;
512 char* resA;
513
514 if (aStr == NULL)
515 return NULL;
516
517 if (hHeap == 0)
518 hHeap = GetProcessHeap();
519
520 chLen = strlen(aStr);
521
522 bLen = (chLen + 1) * sizeof(char);
523
524 resA = HeapAlloc(hHeap, 0, bLen);
525 RtlCopyMemory(resA, aStr, bLen);
526 return resA;
527}

◆ StrCpyHeapAllocW()

WCHAR * StrCpyHeapAllocW ( _In_opt_ HANDLE  hHeap,
_In_ WCHAR wStr 
)

Definition at line 484 of file mswhelper.c.

486{
487 size_t chLen;
488 size_t bLen;
489 WCHAR* resW;
490
491 if (wStr == NULL)
492 return NULL;
493
494 if (hHeap == 0)
495 hHeap = GetProcessHeap();
496
497 chLen = wcslen(wStr);
498
499 bLen = (chLen + 1) * sizeof(WCHAR);
500
501 resW = HeapAlloc(hHeap, 0, bLen);
502 RtlCopyMemory(resW, wStr, bLen);
503 return resW;
504}

Referenced by NSP_GetHostByNameHeapAllocW(), and NSP_LookupServiceBeginW().

◆ StrW2AHeapAlloc()

char * StrW2AHeapAlloc ( _In_opt_ HANDLE  hHeap,
_In_ WCHAR wStr 
)

Definition at line 442 of file mswhelper.c.

444{
445 int charLen;
446 int aStrByteLen;
447 int ret;
448 char* aStr;
449
450 if (wStr == NULL)
451 return NULL;
452
453 charLen = wcslen(wStr) + 1;
454
455 aStrByteLen = (charLen * sizeof(char));
456
457 if (hHeap == 0)
458 hHeap = GetProcessHeap();
459
460 aStr = HeapAlloc(hHeap, 0, aStrByteLen);
461 if (aStr == NULL)
462 {
463 HeapFree(hHeap, 0, aStr);
464 return NULL;
465 }
466
468 0,
469 wStr,
470 charLen,
471 aStr,
472 aStrByteLen,
473 NULL,
474 NULL);
475 if (ret != aStrByteLen)
476 {
477 HeapFree(hHeap, 0, aStr);
478 return NULL;
479 }
480 return aStr;
481}

Referenced by NSP_GetServiceByNameHeapAllocW(), and NSP_LookupServiceNextW().