If you’ve read my previous post, you know that I’m opening up some of the source code from my old startup, Nitrogen Logic. Here’s the first major piece of the Nitrogen Logic source code to go open source. It’s a core utility library used by all of Nitrogen Logic’s C projects, called nlutils.
Because of C’s very limited standard library compared to more modern and full-featured languages, it’s incredibly common for developers to write their own core data structures and helper functions that they use over and over. These include better string manipulation functions, linked lists, associative arrays, etc. – things that we take for granted in languages like Ruby.
nlutils is the set of such tools for Nitrogen Logic’s C projects. Where
possible the code adheres to C99 and POSIX.1-2008. The header files
are thoroughly documented, so browse around the
include/ directory to see what
nlutils provides. After meticulously reviewing the code and tests, I’ve pushed
it to GitHub under the GNU AGPLv3 license for all to enjoy.
The main purpose of nlutils is to augment the C standard library with additional data structures and functions I needed when writing other C projects, such as the Depth Camera Controller’s Kinect interface daemon and the Automation Controller’s automation logic system. There are also a few things related to the web UI of the controllers themselves.
Some of the C functions:
- Arithmetic functions for
struct timespec(why these aren’t present in POSIX is a bit of a mystery to me).
- Thread management functions that provide a slightly simpler interface than POSIX threads and allow renaming threads.
- A variant datatype that can store int, float, string, or raw data values
- Process management and process I/O helpers, including functions for reading the entire output of a process into a string and variations on a popen3() function for controlling process I/O.
- An asynchronous wrapper for the
curlcommand for making process-isolated HTTP requests.
- String splitting, comparison, conversion, and escaping functions.
What’s it made out of?
Nlutils is mostly C, with some tools written as Bash scripts. There’s also a bit of Ruby, some HTML, and the build scripts that tie everything together. I cleaned up all of the bit rot and made sure everything works on Ubuntu 18.04.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
The library also has a test suite that runs under Valgrind by default. Tests are run automatically on Travis CI when a new commit is pushed.
It’s on GitHub
So check out nlutils on GitHub, and keep an eye here for future releases of more Nitrogen Logic source code.