A reinvention of some commonly disputed wheels which vary in availability between GNU and BSD systems of various types and versions for the purpose of the prevention of further wheel reinvention.
libstrl is an attempt to address the strlcpy() problem. BSD systems ship with strlcpy(), strlcat(), wcslcpy(), and wcslcat(); GNU systems ship with strnlen(), wcsnlen(), getline(), and getdelim(). Both the strl* and strn* families of functions have valid uses, though the intent of this page is not to explore the stigma around either of these functions. This library is meant to discourage developers from bundling their own versions of the respective functions for portability's sake.
If your program uses the strlcpy() function, for example, and the developer is willing to create a dependency on libstrl, the hassle of bundling an implementation of strlcpy() can be replaced with the following code:
configure.ac: PKG_CHECK_MODULES([LIBSTRL], [libstrl])
Makefile.am: AM_LDFLAGS = $(LIBSTRL_LIBS) AM_CPPFAGS = $(LIBSTRL_CFLAGS)
myfile.c: #include <strl.h>
There are instructions for building libstrl below.
Please see the HTML documentation on libstrl.h.
Grab a tarball.
Added asprintf() and vasprintf() implementations. These implementations require snprintf(NULL, 0, fmt, ...) (which nearly every even less modern machine seems to have) to be working.
Added strndup(). Fixed the getline() and getdelim() functions which failed to handle the end-of-file condition at all.
Add getline() and getdelim(), two indispensable functions available on all GNU systems but not on MacOSX 10.5 (and possibly not on other BSDs?).
First version where all of the included functions seem to work similarly to the accepted standards for these functions. strlcpy(), strlcat(), strnlen(), wcslcpy(), wcslcat(), wcsnlen().
If you are interested in improving libstrl, please consult binki first. Clone the libstrl mercurial repository:
$ hg clone https://ohnopub.net/hg/libstrl
Submit patches or the output of hg export to libstrl's bug tracker.
During development, be sure to build libstrl with --enable-force-build and --with-check. If you are fixing something in the testsuite itself, please test that portion of the test suite against libstrl's own code (using --enable-force-build) and against an OS's version (by finding a system that provides that function and using --disable-force-build).
Various ./configure options.
I had Gentoo bug 351941 opened for this and dev-libs/libstrl is now in portage (and maintained by me).