Skip to content

Instantly share code, notes, and snippets.

#include <sys/types.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
@nakst
nakst / ini.h
Created May 20, 2021 17:26
ini parser
struct INIState {
char *buffer, *section, *key, *value;
size_t bytes, sectionBytes, keyBytes, valueBytes;
};
bool INIParse(INIState *s) {
#define INI_READ(destination, counter, c1, c2) \
s->destination = s->buffer, s->counter = 0; \
while (s->bytes && *s->buffer != c1 && *s->buffer != c2) s->counter++, s->buffer++, s->bytes--; \
if (s->bytes && *s->buffer == c1) s->buffer++, s->bytes--;
// NOTE Compile without fast math flags.
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.