What c lib to use when I need to parse a simple config file under linux?

Viewed 39559

Let's say I have a simple config file that my c program needs to read/parse.

Let's say it looks a little bit like this:

#Some comment
key1=data1
key2=data2

Is there a standard c lib that I can use instead of writing my own parser?

Thanks Johan


Note: Today I have my own little parser, but there must be some standard libs that solves this simple problem.

7 Answers

libconfig but it does quite more than what you're asking

Why not just use GLIB?

Among countless other things it has library functions for parsing INI like configuration files:

https://developer.gnome.org/glib/stable/glib-Key-value-file-parser.html

Apart from that it also supports Datatypes (Lists, Hashtables, Strings, Caches), Threading, platform neutral abstractions, unit testing, error handling and lots of other great stuff.

For me it's the most useful C library and I would need to have a very good reason to write a C program without using this library.

Related