|
htils 1
A small set of utilities for C programming.
|
A set of small utilities for C, primarily targeting Linux. This page is the API overview; each header under include/htils carries the full documentation, and the project README covers building.
arena_t is a reserve-and-commit arena allocator. Allocate with arena_alloc or arena_alloc_zeroed, roll back to a saved position with arena_dealloc_to, and reclaim the whole arena with arena_clear; arena_free releases the backing memory.
temp_arena_t is a scoped child of an arena: it snapshots the parent on temp_arena_new and restores it on temp_arena_free.
string is a growable byte string; string_slice is a non-owning view over one. Concatenate with string_concat, string_concatb and string_concatf, compare with stringcmp and stringcmpb, search with string_findc and string_find_sstr, split with string_split, and trim with string_trim / string_trim_left / string_trim_right.
htils_assert reports the failed expression and exits, instead of aborting.
stringmap_t is a string-keyed map. Insert with sm_insert and remove with sm_kill; operations return a stringmap_result_t.
Filesystem path helpers: does_path_exist, make_dir and path_remove.
Header-only, type-agnostic dynamic arrays. Create one with da_new, append with da_append, and inspect or trim with da_len, da_cap, da_last, da_pop and da_clear.
Read a whole file with read_file (or read_file_bytes for a prefix) and write with write_to_file / write_to_file_bytes; the *_stream variants take a FILE *.
htils_cli_t is a small argument parser: register options with cli_add and parse with parse_cli.
htils_dotenv_load parses a .env file.
Thread-safe builds only. htils_worker_t runs tasks off the main thread: configure with htils_worker_config_t (htils_worker_config_default), then htils_worker_spawn for a single-shot task or htils_worker_spawn_task for a sliced one. Tasks can poll htils_worker_should_stop and check htils_worker_paused.
A tiny test framework: declare a test with HTILS_TEST, run it with HTILS_TEST_RUN, assert with HTILS_TEST_ASSERT, and finish with HTILS_TEST_RESULT.