mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 08:23:01 +00:00
Dynamically resize buffer as needed
svn path=/trunk/; revision=12350
This commit is contained in:
parent
8bbd20efdc
commit
e4514c3fed
1 changed files with 21 additions and 12 deletions
|
@ -706,7 +706,7 @@ int main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate buffer */
|
/* Allocate buffer */
|
||||||
dwSize = 1024;
|
dwSize = 2048;
|
||||||
lpBuffer = malloc(dwSize);
|
lpBuffer = malloc(dwSize);
|
||||||
if (lpBuffer == NULL)
|
if (lpBuffer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -715,19 +715,28 @@ int main (int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
lError = RegQueryValueEx(hPnpKey,
|
lError = RegQueryValueEx(hPnpKey,
|
||||||
"Configuration Data",
|
"Configuration Data",
|
||||||
NULL,
|
NULL,
|
||||||
&dwType,
|
&dwType,
|
||||||
(LPBYTE)lpBuffer,
|
(LPBYTE)lpBuffer,
|
||||||
&dwSize);
|
&dwSize);
|
||||||
if (lError != ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
if (lError == ERROR_MORE_DATA)
|
if (lError == ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
printf("Need to resize buffer to %lu\n", dwSize);
|
lpBuffer = realloc(lpBuffer, dwSize);
|
||||||
|
if (lpBuffer == NULL)
|
||||||
|
{
|
||||||
|
printf("Error: realloc() of %u bytes failed\n", (unsigned) dwSize);
|
||||||
|
RegCloseKey(hPnpKey);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (lError == ERROR_MORE_DATA);
|
||||||
|
if (lError != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
printf("Failed to read 'Configuration Data' value\n");
|
printf("Failed to read 'Configuration Data' value\n");
|
||||||
free(lpBuffer);
|
free(lpBuffer);
|
||||||
RegCloseKey(hPnpKey);
|
RegCloseKey(hPnpKey);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue