The Wanderinghorse.net Utilities ("whut") is a C99-compliant library with generic, app-agnostic utility code.
This is mostly stuff i end up dragging from tree to tree, consolidated in one place to simplify further dragging.
This tree is really only for my own use. It has no API stability guarantees.
Licenses: this tree amalgamates many years of code from disparate projects and has sources with a mix of licenses, including:
- The SQLite Blessing
- Public Domain dedication
- MIT
- BSD-2 style
All licenses are permissive. It contains no virally-licensed code.
Canonical home: https://fossil.wanderinghorse.net/r/whut
Maintainer: Stephan Beal
Overview
The API provides the following core features:
- Lots and lots of docs.
- A trivial generic interface for streamable input and output from/to arbitrary endpoints.
- A
printf()like API which sends its results to an arbitrary destination using the output stream absraction. This support includes formatting of JSON strings, as well as SQL identifiers and strings (the latter a feature it inherits from its origins in SQLite, way back around 2008). - A general-purposes memory buffer (
whut_blob) which is easily the single-most reused piece of code in my entire coding toolbox. These can be streamed via the I/O abstraction, so can also be formatted inprintf()-like ways, populated from arbitrary streable sources, and streamed to arbitrary streamable destinations.
Seriously: if there's one part of this library worth stripping out and re-using, it's the blob class. - Basic timers for instrumenting code.
- An Pseudo-RNG abstraction and two reference implementations.
- Various filesystem-related APIs, many of which are near-clones of standard C or POSIX routines which bend over backwards to work on Windows and that other OS. It includes helpers for normalizing filenames, searching for files in a search path, and recursively delving into directories.
- Hashing APIs for MD5, "hardened" SHA112, and various flavors of SHA3. These support the input stream interface, making it trivial to hash just about anything.
- Utilities specifically for CLI-style apps, e.g. flag parsing and a callback-based generic REPL.
- All memory allocation is gated behind a single stateful allocator object which clients can replace (e.g. with an abort-on OOM allocator (which the library also provides)).
- An optional SQLite3 wrapper,
whut_db, which has seen some 12 years (as of 2025-08) of good use in the libfossil project. Details for activating these pieces can be found below.
Non-features:
- Single-threaded throughout.
Examples
See the as-yet-basic test app.
Amalgamation Build
This project's code is designed to be "amalgamated" into a two-file
distribution, libwhut.h and libwhut.c, which provide the complete
library. It can be downloaded from this
project's main site or created from a checkout of the source tree:
$ ./configure $ ./make-amalgamation.sh # or: $ ./make-amalgamation.sh -zip # also builds a zipped bundleSidebar: though that works from an out-of-tree build, the results will not be byte-for-byte identical with one created from a local checkout because its code comments will include full paths to the input files. Only code comments are affected.
That will result in the two files. To make use of them in another tree:
#include "libwhut.h"- Compile
libwhut.c - Link the app with
libwhut.o - For small projects,
libwhut.ccan be compiled directly in like:
cc -o myapp -I. my.c libwhut.c - When
libwhut.horlibwhut.care compiled with-DHAVE_CONFIG_Hthen they will#include "config.h"before whut's own compile-time configuration bits are set up, so that any overridable parts of it can be configured from there.
To add optional support:
SQLite:
- Extend the compiler flags for
libwhut.cto add-DWHUT_HAVE_SQLITE3=1and any-I/pathflag which may be necessary to locate"sqlite3.h". - Link to
sqlite3.oorlibsqlite3.aorlibsqlite3.so, plus dependency libraries (typically-lpthreadand-lm), as appropriate for the build. - In files using
libwhut.h, do includesqlite3.hbefore includinglibwhut.h, which will enablelibwhut.hto expose its wrapper APIs.
- Extend the compiler flags for
Line editing: used only by the
whut_cli_rdln()andwhut_cli_repl()pieces. If no line-editing support is enbled, it falls back to usingfgets(3).- Compile
libwhut.cwith one of-DWHUT_ENABLE_LINENOISE=1OR-DWHUT_ENABLE_READLINE=1. - Link against the appropriate libraries or (in the case of linenoise) object file.
- Compile