/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
- * FILE: subsys/system/usetup/inicache.c
+ * FILE: base/setup/usetup/inicache.c
* PURPOSE: INI file parser that caches contents of INI file in memory
* PROGRAMMER: Royce Mitchell III
* Eric Kohl
PINICACHEKEY Next;
if (Key == NULL)
- {
return NULL;
- }
Next = Key->Next;
if (Key->Name != NULL)
PINICACHESECTION Next;
if (Section == NULL)
- {
return NULL;
- }
Next = Section->Next;
while (Section->FirstKey != NULL)
}
Key = (PINICACHEKEY)RtlAllocateHeap(ProcessHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(INICACHEKEY));
if (Key == NULL)
{
return NULL;
}
- RtlZeroMemory(Key,
- sizeof(INICACHEKEY));
-
Key->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap,
0,
(NameLength + 1) * sizeof(WCHAR));
}
-#if 0
-static
-PINICACHESECTION
-IniCacheFindSection(
- PINICACHE Cache,
- PWCHAR Name,
- ULONG NameLength)
-{
- PINICACHESECTION Section = NULL;
-
- if (Cache == NULL || Name == NULL || NameLength == 0)
- {
- return NULL;
- }
-
- Section = Cache->FirstSection;
-
- /* iterate through list of sections */
- while (Section != NULL)
- {
- if (NameLength == wcslen(Section->Name))
- {
- /* are the contents the same too? */
- if (_wcsnicmp(Section->Name, Name, NameLength) == 0)
- break;
- }
-
- /* get the next section*/
- Section = Section->Next;
- }
-
- return Section;
-}
-#endif
-
-
static
PINICACHESECTION
IniCacheAddSection(
}
Section = (PINICACHESECTION)RtlAllocateHeap(ProcessHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(INICACHESECTION));
if (Section == NULL)
{
return NULL;
}
- RtlZeroMemory(Section, sizeof(INICACHESECTION));
-
/* Allocate and initialize section name */
Section->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap,
0,
*NamePtr = NULL;
*NameSize = 0;
- /* skip whitespace */
+ /* Skip whitespace */
while (*Ptr != 0 && isspace(*Ptr))
{
Ptr++;
*NameSize = 0;
Size = 0;
- /* skip whitespace and empty lines */
+ /* Skip whitespace and empty lines */
while (isspace(*Ptr) || *Ptr == '\n' || *Ptr == '\r')
{
Ptr++;
NTSTATUS
IniCacheLoad(
PINICACHE *Cache,
- PUNICODE_STRING FileName,
+ PWCHAR FileName,
BOOLEAN String)
{
+ UNICODE_STRING Name;
OBJECT_ATTRIBUTES ObjectAttributes;
FILE_STANDARD_INFORMATION FileInfo;
IO_STATUS_BLOCK IoStatusBlock;
*Cache = NULL;
/* Open ini file */
+ RtlInitUnicodeString(&Name, FileName);
+
InitializeObjectAttributes(&ObjectAttributes,
- FileName,
+ &Name,
0,
NULL,
NULL);
DPRINT("File size: %lu\n", FileLength);
- /* Allocate file buffer */
+ /* Allocate file buffer with NULL-terminator */
FileBuffer = (CHAR*)RtlAllocateHeap(ProcessHeap,
0,
FileLength + 1);
&FileOffset,
NULL);
- /* Append string terminator */
+ /* Append NULL-terminator */
FileBuffer[FileLength] = 0;
NtClose(FileHandle);
/* Allocate inicache header */
*Cache = (PINICACHE)RtlAllocateHeap(ProcessHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(INICACHE));
if (*Cache == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
- /* Initialize inicache header */
- RtlZeroMemory(*Cache, sizeof(INICACHE));
-
/* Parse ini file */
Section = NULL;
Ptr = FileBuffer;
PINICACHE Cache)
{
if (Cache == NULL)
- {
return;
- }
while (Cache->FirstSection != NULL)
{
/* Allocate key buffer */
Key = (PINICACHEKEY)RtlAllocateHeap(ProcessHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(INICACHEKEY));
if (Key == NULL)
{
return NULL;
}
- RtlZeroMemory(Key, sizeof(INICACHEKEY));
-
/* Allocate name buffer */
Key->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap,
0,
/* Allocate inicache header */
Cache = (PINICACHE)RtlAllocateHeap(ProcessHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(INICACHE));
if (Cache == NULL)
{
return NULL;
}
- /* Initialize inicache header */
- RtlZeroMemory(Cache, sizeof(INICACHE));
-
return Cache;
}
Section = Section->Next;
if (Section != NULL)
- BufferSize += 2; /* extra "\r\n" at end of each section */
+ BufferSize += 2; /* Extra "\r\n" at end of each section */
}
- BufferSize++; /* Null-terminator */
DPRINT("BufferSize: %lu\n", BufferSize);
- /* Allocate file buffer */
+ /* Allocate file buffer with NULL-terminator */
Buffer = (CHAR*)RtlAllocateHeap(ProcessHeap,
- 0,
- BufferSize);
+ HEAP_ZERO_MEMORY,
+ BufferSize + 1);
if (Buffer == NULL)
{
DPRINT1("RtlAllocateHeap() failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
- RtlZeroMemory(Buffer, BufferSize);
-
/* Fill file buffer */
Ptr = Buffer;
Section = Cache->FirstSection;
}
/* Create ini file */
- RtlInitUnicodeString(&Name,
- FileName);
+ RtlInitUnicodeString(&Name, FileName);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
}
Section = (PINICACHESECTION)RtlAllocateHeap(ProcessHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(INICACHESECTION));
if (Section == NULL)
{
return NULL;
}
- RtlZeroMemory(Section, sizeof(INICACHESECTION));
-
/* Allocate and initialize section name */
Section->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap,
0,