Introducing Clib

Micro C Libraries & package manager

TJ Holowaychuk
2 min readOct 11, 2013

Despite the ubiquitous nature of C it’s sometimes difficult to find just what you need, and you’re especially lucky if it’s not part of some gigantic library of unrelated code. For this reason I’ve decided to create Clib, a GitHub organization aimed at providing small, focused, discoverable “micro libraries”.

Using Clib

Clib is a suite of small C libraries that you can manually copy/paste into your project, or you can use the clib C package manager to install and search for existing packages that exist in the registry — just a plain old GitHub wiki page.

The libraries you install with clib(1) do not require a build step, these are just plain old C source files. This also means that clib does not provide “true” modularity since that would require a build step and name mangling.

Conversely this means that clib(1) can easily fit into your existing C tool-chain without friction, as the source files just become part of your repository, and do not rely on clib(1) for any portion of the build.

Installing Packages

Install packages with the GitHub <user>/<repo> combo, or when the <user> is “clibs” you may omit the username:

$ clib install file hash install : clibs/file
install : clibs/hash
fetch : hash.c
fetch : hash.h
fetch : khash.h
fetch : src/file.c
fetch : src/file.h
write : deps/hash.c — 3.6kb
write : deps/file.h — 261b
write : deps/file.c — 893b
write : deps/hash.h — 1.59kb
write : deps/khash.h — 11.11kb

Clib also supports “install” scripts so you may build & install executables:

$ clib install visionmedia/watch install : visionmedia/watch
fetch : https://github.com/visionmedia/watch/archive/0.2.1.tar.gz
unpack : /tmp/visionmedia-watch
exec : make install
λ clib (master): watch —version
0.2.1

Discovering Packages

With the clibs registry it’s easy to discover packages via the wiki page, or the clib-search(1) executable, passing zero or more keywords:

$ clib search trim nami-doc/trim.c
url: https://github.com/nami-doc/trim.c
desc: trim a string, in place
stephenmathieson/trim.c
url: https://github.com/stephenmathieson/trim.c
desc: string trim with left and right support

HINT: on osx hold cmd and dbl-click a url to open it in the browser for review.

Future

This is obviously not a fool-proof approach but it’s a reasonable quick & dirty solution.

If you’re interested in contributing to https://github.com/clibs leave a note with your username and I’ll add you to the organization.

That’s all for now!

--

--