NOTICE: libmisc is now deprecated. Please see Smol C Libs for an equivalent replacement
This repo contains useful functions and files that I use often. Eventually I hope it might turn into a “standard library” of sorts that has lots of useful stuff I can copy into my C projects when necessary.
All code in this repo is ISO C99—no POSIX extensions, no glibc extensions, no compiler extensions. At least, it should all be C99. Email me if it isn't!
Simply add this repo as a subrepo
or submodule. Then add a rule to run
make in this directory to build a
libmisc.a library, and simply link that in with the rest of your
project. You can then use the relevant headers. For an example of using
libmisc as a library, see a sample makefile at
You can also copy individual files into your project as well. You should be sure to copy both the header and accompanying C file. The version of a file is included at the very top so you can easily check for updates in the future (note that the versions are not correlated, and different pairs of files may have different versions).
If you're worried about manually copying individual files in, updating isn't as important here because everything should be simple, relatively unchanging, and not security-critical, where not updating would mean you just miss out on getting new files and functions rather than getting updates to existing ones.
.c files have an optional dependency on
testing.h. This only
affects you if you are already using
string_util.c contain tests and could be added to your testing setup.
The header comments of the files include more details. All
.h files contain
extensive documentation on the functions they contain as well. Simply click on
the file names to see the contents.
Implements a simple arena allocator. It is particularly useful for functions with lots of temporary allocations (string parsing and modification?) as you don't have to keep track of every little allocation, and can instead free all memory used afterwards.
warn family of functions from *BSD. Also includes the
progname pair of functions.
Useful functions for working with plain C strings.
Useful functions for unit testing.
The upstream URL of this project is https://git.sr.ht/~nytpu/libmisc. Send suggestions, bugs, and other contributions to ~firstname.lastname@example.org. For help sending a patch through email, see https://git-send-email.io. You can browse the list archives at https://lists.sr.ht/~nytpu/public-inbox.
Copyright (c) 2021 nytpu <alex [at] nytpu.com>