在Linux上的C中使用INI文件 [英] Use an INI file in C on Linux

查看:369
本文介绍了在Linux上的C中使用INI文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在使用Linux读取类似 INI 文件的配置的标准方法C?

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

我正在基于Linux的手持设备上工作,并用C语言编写代码.

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

否则,我想知道其他选择.

Otherwise, I shall like to know about any alternatives.

最终更新:

我已经探索甚至使用过LibConfig.但是占用空间很大,而且我的用法太简单了.因此,为了减少占用空间,我推出了自己的实现.该实现不是太通用,实际上到目前为止已经相当耦合了.启动应用程序时,配置文件将被解析一次,并设置为一些全局变量.

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.

推荐答案

尝试 libconfig :

一个用于处理结构化配置文件的简单库,如下所示: test.cfg .与XML相比,此文件格式更紧凑,更易读.而且与XML不同,它具有类型感知功能,因此无需在应用程序代码中进行字符串解析.

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 非常紧凑—仅是expat XML解析器库大小的一小部分.这使其非常适合内存受限的系统,例如手持设备.

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.

该库包含针对C和C ++语言的绑定.它可以在POSIX兼容的UNIX和类似UNIX的系统(GNU/Linux,Mac OS X,Solaris,FreeBSD),Android和Windows(2000,XP及更高版本)上运行.

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

这篇关于在Linux上的C中使用INI文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆