Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use an INI file in C on Linux

Tags:

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.

Otherwise, I shall like to know about any alternatives.

Final update:

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 configuration file is parsed once at the time of starting the application and set to some global variables.

like image 297
Kangkan Avatar asked Feb 17 '10 11:02

Kangkan


People also ask

How do I use a .INI file?

How to Open and Edit INI Files. It's not a common practice for people to open or edit INI files, but they can be opened and changed with any text editor. Just double-clicking it will automatically open it in the Notepad application in Windows.

What is .INI file in Linux?

An INI file is a configuration file for computer software that consists of a text-based content with a structure and syntax comprising key–value pairs for properties, and sections that organize the properties.

Where is INI file in Linux?

ini file is in the /etc/opt/mqm directory on UNIX and Linux systems.


1 Answers

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

like image 115
shuvalov Avatar answered Sep 21 '22 14:09

shuvalov