Info • Install • Usage • License
A header-only C library for serializing and de-serializing .ini files.
If you think this library could be of use to you, I'd recommend that you first and foremost study the source code on your own.
Simply clone or copy-paste inilite.h into your codebase and include it.
#define INILITE_IMPLEMENTATION
#include "inilite.h"Regarding ownership: the IniSection/Ini structs keep ownership of memory. The get
functions only return references that would need to be properly copied if you want to
keep using them after Ini_free().
Ini ini_in = {0};
Ini_init(&ini_in, content_of_ini_file);
IniSection *ini_db = Ini_get_section(&ini_in, "database");
printf("name: %s\n", IniSection_get_value(ini_db, "name"));
Ini_free(&ini_in);Serialization is done procedurally. I chose this approach since it makes it
trivial to (for example) iterate on an array to save its values to an .ini file through a simple for-loop.
Ini ini_out = {0};
Ini_init(&ini_out, NULL);
Ini_append_section(&ini_out, "gojo");
Ini_append_kv(&ini_out, "name", "Satoru Gojo");
Ini_append_kv(&ini_out, "occupation", "Jujutsu Sorcerer");
Ini_append_kv(&ini_out, "birthday", "December 7, 1989");
Ini_append_section(&ini_out, "itadori");
Ini_append_kv(&ini_out, "name", "Yuji Itadori");
Ini_append_kv(&ini_out, "occupation", "Jujutsu Sorcerer, Student");
Ini_append_kv(&ini_out, "birthday", "March 20, 2003");
char new_content[128 * 100] = {0};
Ini_build(&ini_out, new_content);
Ini_free(&ini_out);
FILE *output = fopen("output.ini", "w");
fprintf(output, "%s", new_content);This project is licensed under the MIT License.