~nytpu/smol-c-libs

Single-header or two-file C libraries

2706138 fix license issue

~nytpu pushed to ~nytpu/testing.h git

3 days ago

d373f52 fix license issue

3 days ago

#Smol C Libs — Single-header or two-file C libraries

I have a tendency to break out small stuff I write in C into their own libraries on the off-chance I need to use it in the future. This project provides a place for me to consolidate those libraries.

#Library List

#arena.c

license: MPL-2.0 standards: C99 version: 3.0.0 builds.sr.ht status

Implements a simple arena allocator. It is particularly useful for functions with lots of temporary allocations (strings, linked lists, etc.) as you don't have to keep track of every little allocation, and can instead free all memory used afterwards.

#err.c

license: MPL-2.0 standards: C99 version: 2.0.0

Contains the err and warn family of functions from *BSD. Also includes the {get,set}progname pair of functions.

#string_util.c

license: MPL-2.0 standards: C99 version: 2.1.0 builds.sr.ht status

Useful functions for creating and manipulating plain C strings.

#testing.h

license: BSL-1.0 standards: C99 version: 2.0.0

Simple unit testing.

#xdgbasedir.c

license: BSL-1.0 standards: C99 version: 1.1.0

Find data, cache, configuration, and more directories, following the XDG Base Directory Specification.

#Documentation

Most of the header files are meant to be self-documenting and should have comprehensive comments describing usage. More complex libraries may have a comment in the header with further explanation.

#Installing

Simply add the library you want as a subrepo or submodule. Then add the source file (if any) to your build system and include the header where necessary.

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 libraries 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 functions and features rather than getting updates to existing ones.

Some .c files have an optional dependency on testing.h. This only affects you if you are already using testing.h, but arena.c and string_util.c contain tests and could be added to your testing setup.

#Contributing

The upstream URL of this project is https://sr.ht/~nytpu/smol-c-libs. Send suggestions, bugs, patches, and other contributions to ~nytpu/public-inbox@lists.sr.ht. 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.