commit | 88d38365a92e9226497dde3a16705399876fe54c | [log] [tgz] |
---|---|---|
author | Leonard Chan <leonardchan@google.com> | Wed Jun 07 03:11:45 2023 +0000 |
committer | Leonard Chan <leonardchan@google.com> | Wed Jun 07 03:11:45 2023 +0000 |
tree | 12666308bdef4ec87e632b20da69e63fe4823fd8 | |
parent | 1b9ee30b8380dfed8d9fe8ab59ad1a04515824b7 [diff] |
[inih] Change void* to FILE* UBSan was complaining about a function type mismatch on a call to an ini_reader. The function shoulod essentially match the prototype for fgets, but differs in the last argument which should be a FILE*. Bug: 128274 Change-Id: I34ba7fc90d087ba6e48bcf95c48c1a066bf16ad2
This is a header only C++ version of inih.
inih (INI Not Invented Here) is a simple .INI file parser written in C. It‘s only a couple of pages of code, and it was designed to be small and simple, so it’s good for embedded systems. It‘s also more or less compatible with Python’s ConfigParser style of .INI files, including RFC 822-style multi-line syntax and name: value
entries.
All you need to do is to include INIReader.h
. Consider the following example (INIReaderTest.cpp
):
#include <iostream> #include "INIReader.h" int main() { INIReader reader("test.ini"); if (reader.ParseError() != 0) { std::cout << "Can't load 'test.ini'\n"; return 1; } std::cout << "Config loaded from 'test.ini': version=" << reader.GetInteger("protocol", "version", -1) << ", name=" << reader.Get("user", "name", "UNKNOWN") << ", email=" << reader.Get("user", "email", "UNKNOWN") << ", pi=" << reader.GetReal("user", "pi", -1) << ", active=" << reader.GetBoolean("user", "active", true) << "\n"; return 0; }
To compile and run:
g++ INIReaderTest.cpp -o INIReaderTest.out ./INIReaderTest.out # Config loaded from 'test.ini': version=6, name=Bob Smith, email=bob@smith.com, pi=3.14159, active=1