Use an INI file in C on Linux

后端 未结 7 1548
不思量自难忘°
不思量自难忘° 2020-12-14 17:34

Is there a standard way of reading a kind of configuration like INI files for Linux using C?

I am working on a Linux based handheld and writing code in C.

Ot

相关标签:
7条回答
  • 2020-12-14 18:01

    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, though. That might be helpful.

    0 讨论(0)
  • 2020-12-14 18:01

    If you need a fast and small code just for reading config files I suggest the inih

    It loads the config file content just once, parse the content and calls a callback function for each key/value pair.

    Really small. It can be used on embedded systems too.

    0 讨论(0)
  • 2020-12-14 18:04

    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".

    0 讨论(0)
  • 2020-12-14 18:07

    Here are four options:

    1. Iniparser
    2. libini
    3. sdl-cfg
    4. RWini
    0 讨论(0)
  • 2020-12-14 18:09

    I hate to suggest something entirely different in suggesting XML, but libexpat is pretty minimal, but does XML.

    I came to this conclusion as I had the same question as you did, but then I realized the project already had libexpat linked-in--and I should probably just use that.

    0 讨论(0)
  • 2020-12-14 18:16

    Try libconfig:

    a simple library for processing structured configuration files, like this one: test.cfg. This file format is more compact and more readable than XML. And unlike XML, it is type-aware, so it is not necessary to do string parsing in application code.

    Libconfig is very compact — a fraction of the size of the expat XML parser library. This makes it well-suited for memory-constrained systems like handheld devices.

    The library includes bindings for both the C and C++ languages. It works on POSIX-compliant UNIX and UNIX-like systems (GNU/Linux, Mac OS X, Solaris, FreeBSD), Android, and Windows (2000, XP and later)...

    0 讨论(0)
提交回复
热议问题