Utilties for the discerning C programmer
This document gives a quick overview of each module/sub-library included in nonlibc.
If you need a non-crypto hash, odds are you want FNV1A.
This is the simplest, least-hassle implementation I know of.
Usage examples in fnv_test.c.
An fnvsum
utility is also provided for hashing files (or stdin),
on the pattern of md5sum
.
See the fnvsum man page
If you would like to use fnvsum
without installing:
$ make
$ # hash stdin:
$ echo -n '' | build-release/util/fnvsum
cbf29ce484222325 -
$ # hash a file:
$ build-release/util/fnvsum /path/to/some/file
Sometimes what you DON’T want is floating-point math.
This library has sane implementations for:
Oh, and they’re all inlines so your compiler can reason about local variables and turn out decent assembly.
Every function is shown used in nmath_test.c
That’s done by hx2b.h and b2hx.h.
Check out hex2bin2hex_test.c for the full monte.
This is a simple, clean, fast implementation of PCG.
That matters more than you may think - and anyways this API is simple and clean.
Check out the test code at pcg_rand_test.c.
The fastest possible way I know to push/pop pointer-sized values onto a stack, which grows (reallocates memory) as necessary, and can be kept around between function calls.
Use the nlc_timing_start()
and nlc_timing_stop()
macros in nonlibc.h.
See e.g.: fnv_test.c for usage examples.
This header helps with the following annoyances:
printf
statementprintf
s inside conditionals increase code size
for no good reasongrep
for it
because you don’t remember which source file it was in__FILE__
and __LINE__
Some usage examples are in zed_dbg_test.c; zed_dbg.h itself is fairly well commented also.
A memory allocator which handles zero-copy I/O behind-the-scenes.
An example usage is the ncp utility provided by this library.
ncp
re-implements the system cp
command using this library for zero-copy I/O;
and is >20% faster than cp
for large files.
TODO