https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d21ffe6336b327894a9f8…
commit d21ffe6336b327894a9f85daf0da7c6b0089e3b2
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Fri Aug 2 23:32:30 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Tue Aug 6 23:39:53 2019 +0200
[FREELDR] Add an INI helper that allows modifying an existing setting's value in
memory.
---
boot/freeldr/freeldr/include/inifile.h | 1 +
boot/freeldr/freeldr/lib/inifile/inifile.c | 41 ++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/boot/freeldr/freeldr/include/inifile.h
b/boot/freeldr/freeldr/include/inifile.h
index 9bed7004d17..0bc8e60968a 100644
--- a/boot/freeldr/freeldr/include/inifile.h
+++ b/boot/freeldr/freeldr/include/inifile.h
@@ -81,4 +81,5 @@ BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG
SettingNumber, PCHA
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer,
ULONG BufferSize);
BOOLEAN IniAddSection(PCSTR SectionName, ULONG_PTR* SectionId);
BOOLEAN IniAddSettingValueToSection(ULONG_PTR SectionId, PCSTR SettingName, PCSTR
SettingValue);
+BOOLEAN IniModifySettingValue(ULONG_PTR SectionId, PCSTR SettingName, PCSTR
SettingValue);
VOID IniCleanup(VOID);
diff --git a/boot/freeldr/freeldr/lib/inifile/inifile.c
b/boot/freeldr/freeldr/lib/inifile/inifile.c
index ba1d5b214ec..fa231e8518d 100644
--- a/boot/freeldr/freeldr/lib/inifile/inifile.c
+++ b/boot/freeldr/freeldr/lib/inifile/inifile.c
@@ -289,3 +289,44 @@ BOOLEAN IniAddSettingValueToSection(ULONG_PTR SectionId, PCSTR
SettingName, PCST
return TRUE;
}
+
+BOOLEAN IniModifySettingValue(ULONG_PTR SectionId, PCSTR SettingName, PCSTR
SettingValue)
+{
+ PINI_SECTION Section = (PINI_SECTION)SectionId;
+ PINI_SECTION_ITEM SectionItem;
+ PCHAR NewItemValue;
+
+ // Loop through each section item and find the one we want
+ SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM,
ListEntry);
+ while (&SectionItem->ListEntry != &Section->SectionItemList)
+ {
+ // Check to see if this is the setting we want
+ if (_stricmp(SectionItem->ItemName, SettingName) == 0)
+ {
+ break;
+ }
+
+ // Nope, keep going
+ // Get the next section item in the list
+ SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink,
INI_SECTION_ITEM, ListEntry);
+ }
+ // If the section item does not exist, create it
+ if (&SectionItem->ListEntry == &Section->SectionItemList)
+ {
+ return IniAddSettingValueToSection(SectionId, SettingName, SettingValue);
+ }
+
+ // Reallocate the new setting value buffer
+ NewItemValue = FrLdrTempAlloc(strlen(SettingValue) + 1, TAG_INI_VALUE);
+ if (!NewItemValue)
+ {
+ // We failed, bail out
+ return FALSE;
+ }
+ FrLdrTempFree(SectionItem->ItemValue, TAG_INI_VALUE);
+ SectionItem->ItemValue = NewItemValue;
+
+ strcpy(SectionItem->ItemValue, SettingValue);
+
+ return TRUE;
+}