descriptionC99 single-header implementation of common libc extensions
last changeMon, 18 May 2026 15:48:12 +0000 (11:48 -0400)
content tags
readme

A collection of portable, strict C99, single-header implementations of common libc extensions.

All functions are implemented as macros expanding to an internal function reference, this allows to use the headers with no meta build system - it compiles even if the extensions are already present, see How to on disabling this behaviour.

How to

Include the header in every file needed as usual:

#include "<ext-func-name>.h"

In the file chosen for the function implementation:

#define <EXT-FUNC-NAME>_IMPLEMENTATION
#include "<ext-func-name.h>"

By default, the header won’t have any stdlib includes, change that with:

#define <EXT-FUNC-NAME>_INCLUDE_LIBC

Or disable function, type and variable override with:

#define HAVE_<EXT-FUNC-NAME>

Specifics


asprintf

includes vasprintf() and asprintf()


fgetln

includes fgetln()


getopt_long

includes getopt(), getsubopt(), getopt_long() and getopt_long_only()

getopt_long.h has additional macros related to argument permuting, defining those enables it per function (GNU behaviour, can still be disabled at runtime by setting $POSIXLY_CORRECT):

#define GETOPT_PERMUTE_ARGS
#define GETOPT_LONG_PERMUTE_ARGS
#define GETOPT_LONG_ONLY_PERMUTE_ARGS

strdup

includes strdup() and strndup()

strndup() follows the latest standard, meaning that it copies at most n chars, not n + 1. Also, no standard specifies that strndup() should return less than n if strlen(s) + 1 < n, but this implementation does so.


strlcat

includes strlcat() and strlcpy()


strtonum

includes strtonum()

shortlog
2026-05-18 gitstrtonum: fix `TOOLARGE` macro name master
2026-05-06 gitadd strtonum
2026-05-03 gitadd fgetln
2026-05-02 gitstrdup: remove unused variable
2026-05-01 gitadd strdup
2026-05-01 gitremove unnecessary stddef include
2026-04-26 gitadd strlcpy, remove estrlcat
2026-04-24 gitadd to readme
2026-04-24 gitadd strlcat
2026-04-20 gitgetopt_long: add program name to warnx
2026-04-20 gitminor asprintf refinement
2026-04-19 gitrevise README
2026-04-19 gitadd getsubopt, improve override macros
2026-04-18 gitremove "program_invocation_short_name" dependency for...
2026-04-18 gitadd getopt_long
2026-04-17 gitrevise function formatting
...
heads
4 weeks ago master