views:

363

answers:

6

Is there any standard way of reading a kind of configuration like ini files for linux using c? I am working on a Linux based hand held and writing code in c.

Otherwise, I shall like to know about any alternatives.

+4  A: 

No, there isn't one standard way. I'm sorry, but that is probably the most precise answer :)

You could look at this list of Linux configuration file libraries, tho. That might be helpful.

gnud
But the least helpful one...
amarillion
funny how the OP asks for a *standard* method, gets 7 *different* suggestions (all modded up) and one answer that says there is *no standard* gets modded down.
SF.
This is technically the correct answer.
Tim Post
Before the edit, the answer just said "no", without giving any hint as to available options. That's why it got -1 from me, because that's about as helpful as hitting F1 on Windows. Now, with the list of options, it's a good answer, and that's why I revert the vote.
DevSolar
It dawned on me that maybe, even though the question asked for a standard way, the author really wanted some different options. But that's not really what he's asking, thus the initial 'no'.
gnud
@gnud: Though I asked for any standard way, the intent is to know the solution to a problem. I understood that the question should have been put in such a way to also get other answers. I am updating the question. Thanks a lot.
Kangkan
+1  A: 

Here is four options :

  1. Iniparser
  2. libini
  3. sdl-cfg
  4. RWini
Boris Guéry
+2  A: 

If you can use the (excellent, in any C-based application) glib, it has a key-value file parser that is suitable for .ini-style files. Of course, you'd also get access to the various (very nice) data structures in glib, "for free".

unwind
+3  A: 

try libconfig: http://www.hyperrealm.com/libconfig/

shuvalov
It seems libconfig is the right chice looking at its simplicity and small size. Thanks a lot.
Kangkan
+2  A: 

There is an updated fork of iniparser at ccan, the original author has not been able to give it much attention over the years. Disclaimer - I maintain it.

Additionally, iniparser contains a dictionary that is very useful on its own.

Tim Post
A: 

I have explored and even used LibConfig. But the footprint is high and my usage is too simple. So, to reduce the footprint, I have rolled out my own implementation. The implementation is not too generic, in fact quite coupled as of now. The config file is parsed once at the time of starting the application and set to some global variables.

Kangkan