tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Reuse strtonum(3) and reallocarray(3) from OpenBSD



Hello,

OpenBSD standardized in its eco-system i.e. two functions:
- reallocarray(3) is a safer drop-in replacement of realloc(3)
- strtonum(3) is yet another function to change literal string to a number

strtonum(3) became a BSD standard (OpenBSD since 3.6 A.D. 2004, FreeBSD since 6.1 A.D. 2004)
reallocarray(3) was introduced in OpenBSD 5.6 (A.D. 2014)

I don't want to start rant how these functions are good or needed, my personal intention is different: easier code share between our BSD systems. To narrow things down, I want to use an unmodified piece of code from the OpenBSD sources - and there pops out this compat problem.

I can see 4 solutions:
- push things upstream and import strtonum(3) and reallocarray(3) to NetBSD's stdlib,
- wrap around a system-wide reusable source-code level OpenBSD compat layer,
- patch Linux specific libbsd for emulation of OpenBSD in the NetBSD environment (I really don't want to do this!),
- all-time patching sources for missing functions and it's not so unmodified anymore (I'm so bored of losing my time on this...).

In reality all current code in OpenBSD reuses these two functions (not counting a few bit more specialized like explicit_bzero(3)).

If we will ever collaborate with OpenBSD with e.g. LibreSSL (not tracking how it is with at least mandoc) these functions are must. The first solution opens possibility to reuse these functions in our eco-system as well, the second one gives me possibility to stop making compat functions anymore for other too.

I'm a volunteer for a public-report with a patch.

Manual pages as references:
http://www.openbsd.org/cgi-bin/man.cgi?query=reallocarray&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strtonum.3?query=strtonum&arch=i386
https://www.freebsd.org/cgi/man.cgi?query=strtonum&apropos=0&sektion=3&manpath=FreeBSD+6.1-RELEASE&arch=default&format=html

http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/bzero.3?query=bzero&arch=i386

Best regards,


Home | Main Index | Thread Index | Old Index