util: add mkdir_p helper

The shl_mkdir_p() helpers implement "mkdir -p" as C function.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add shl_now()

This returns the current time as uint64_t in mircoseconds since EPOCH.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add ratelimit helper

The ratelimit helpers can be used for very simple burst-based
rate-limiting. The shl_ratelimit_test() funciton is the core which just
increases the use-count and makes sure it didn't exceed the given limits.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add typed greedy realloc

The typed variant simplifies working with arrays and greedy_realloc().
Instead of maintaining a size-field, you can now conveniently maintain a
count-field instead. This is way more common and makes this all alot
easier.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
build: order test alphabethically

Reoder all tests alphabetically so we can more easily find them.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
trie: fix memleak in tests

Minor memleak in our test-suite. Doesn't hurt anyone but will break out
future valgrind based tests.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
build: add valgrind memtests

This adds a new make-target: make memcheck
This runs valgrind on all our tests to verify that we didn't leak any
memory.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: correctly clear memory on typed greedy realloc

Fix obvious offset mis-calculation.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: force void** on typed greedy-realloc

Allow any input as type and forcibly cast to void**.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add greedy realloc test-case

Add tests for typed greedy realloc. These become quite useful with the
memcheck test addition to verify allocation sizes.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add shl_qstr_join()

This does the inverse of shl_qstr_tokenize(). Encoding is currently
limited to the required sequences, but more can be added in the future.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add shl_strsplit()

shl_strsplit() is a simplified tokenizer simply splitting strings by a
given set of separators.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
log: protect LOG_XY definitions

If you include syslog.h, you already get the LOG_XY macros. Don't define
them in case they're already defined.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
macro: remove useless *_cleanup_* from cleanup macros

There is no reason to add _cleanup_ to them. It should be obvious that
_shl_free_ is the cleanup-macro for free().

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
dlist: guard _unlink() against unlinked objects

If an object is not linked, don't try to unlink it.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
dlist: add shl_dlist_linked() helper

The shl_dlist_linked() helper checks whether an object is linked into a
list. This must not be used on list-heads but only on list-items.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
util: add shl_isempty() helper

The shl_isempty() helper tests whether a sring is NULL or empty.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
htable: add u64 helpers

Add u64 hash-table helpers. Note that we need to do some limited hashing
in case size_t is not 64bit wide. Other than that, it's a fairly trivial
copy of the unsigned-long helpers.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
htable/dlist: remove custom offsetof macros

Use shl_container_of() instead of the custom copies.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>