INI Parser

Tiny C INI parsing library supporting sections, keys, values, and escape sequences. All in under 300 lines.


Features

Sections
Supports single-level sections. Whitespace is ignored in section names.
Keys
Supports keys. Whitespace is ignored in key names.
Values
Supports values. What you see is what you get.
Escape Sequences
The escape sequences \n, \r, \a, \b, \t, \f, \e, and \\ are supported in values.
Case Insensitive
Sections and keys are case insensitive.
Types
Strings are the only supported type. Use sscanf or itoa to convert strings into integers.

Required Functions

INI Parser is very minimal, only requiring six C standard library functions:

Downloads

File Size Description
ini.c 5.6K INI Parser. Make sure to remove the main function before using.
ini.h 816 INI Parser Header.

API


ini_t* ini_read_file(FILE* f);

Reads an INI file.

Parameters

FILE* f
File to read.

Returns: INI struct generated from the file.


char* ini_get(ini_t* ini, const char* sectionname, const char* keyname);

Gets the value of a key.

Parameters

ini_t* ini
INI struct to search in.
const char* sectionname
Name of section. Use NULL for the default section.
const char* keyname
Name of key.

Returns: The value of a key of NULL on error or if key not found.


void ini_free(ini_t* ini);

Frees an INI struct and its contents.

Parameters

ini_t* ini
INI struct to free.

Timeline

2/3/21
Project started.
2/5/21
Version 1.0.0 released.