libbsd man page

libbsd — utility functions from BSD systems

Description

The libbsd library provides a set if compatibility macros and functions commonly found on BSD-based systems. Its purpose is to make those available on non-BSD based systems to ease portability.

The library can be used in an overlay mode, which is the preferred way, so that the code is portable and requires no modification to the original BSD code. This can be done easily with the pkg-config(3) library named libbsd-overlay. Or by adding the system-specific include directory with the bsd/ suffix to the list of system include paths. With gcc this could be -isystem ${includedir}/bsd. In addition the LIBBSD_OVERLAY pre-processor variable needs to be defined. The includes in this case should be the usual system ones, such as <unistd.h>.

The other way to use the library is to use the namespaced headers, this is less portable as it makes using libbsd mandatory and it will not work on BSD-based systems, and requires modifying original BSD code. This can be done with the pkg-config(3) library named libbsd. The includes in this case should be namespaced with bsd/, such as <bsd/unistd.h>.

The package also provides a bsd-ctor static library that can be used to inject automatic constructors into a program so that the setproctitle() function gets invoked automatically at startup time. This can be done with the pkg-config(3) library named libbsd-ctor.

Headers

The following are the headers provided by libbsd, that extend the standard system headers. They can work in normal or overlay modes, for the former they need to be prefixed with bsd/.

<bitstring.h>
<err.h>
<getopt.h>
<libutil.h>
<md5.h>
<netinet/ip_icmp.h>
<nlist.h>
<readpassphrase.h>
<stdio.h>
<stdlib.h>
<string.h>
<stringlist.h>
<sys/bitstring.h>
<sys/cdefs.h>
<sys/endian.h>
<sys/poll.h>
<sys/queue.h>
<sys/time.h>
<sys/tree.h>
<timeconv.h>
<unistd.h>
<vis.h>
<wchar.h>

The following is a libbsd specific convenience header, that includes some of the extended headers. It only works in non-overlay mode.

<bsd/bsd.h>

Deprecated

Some functions have been deprecated, they will emit warnings at compile time and possibly while being linked at run-time. This might be due to the functions not being portable at all to other systems, making the package not buildable there; not portable in a correct or non-buggy way; or because there are better more portable replacements now.

This is the list of currently deprecated macros and functions:

fgetln()

Unportable, requires assistance from the stdio layer. An implementation has to choose between leaking buffers or being reentrant for a limited amount of streams (this implementation chose the latter with a limit of 32). Use getline(3) instead, which is available in many systems and required by IEEE Std 1003.1-2008 (“POSIX.1”).

funopen()

Unportable, requires assistance from the stdio layer or some hook framework. On GNU systems the fopencookie() function can be used. Otherwise the code needs to be prepared for neither of these functions being available.

In addition, the MD5 set of digest funtions are now provided by the libmd companion library, so it is advised to use that instead, as the ones provided in libbsd might disappear on the next SONAME bump.

See Also

arc4random(3bsd), bitstring(3bsd), byteorder(3bsd), closefrom(3bsd), errc(3bsd), expand_number(3bsd), explicit_bzero(3bsd), fgetln(3bsd), fgetwln(3bsd), flopen(3bsd), fmtcheck(3bsd), fparseln(3bsd), fpurge(3bsd), funopen(3bsd), getbsize(3bsd), getpeereid(3bsd), getprogname(3bsd), heapsort(3bsd), humanize_number(3bsd), md5(3bsd), nlist(3bsd), pidfile(3bsd), queue(3bsd), radixsort(3bsd), readpassphrase(3bsd), reallocarray(3bsd), reallocf(3bsd), setmode(3bsd), setproctitle(3bsd), stringlist(3bsd), strlcpy(3bsd), strmode(3bsd), strnstr(3bsd), strtonum(3bsd), timeradd(3bsd), timeval(3bsd), tree(3bsd), unvis(3bsd), vis(3bsd), wcslcpy(3bsd).

History

The libbsd project started in the Debian GNU/kFreeBSD port as a way to ease porting code from FreeBSD to the GNU-based system. Pretty early on it was generalized and a project created on FreeDesktop.org for other distributions and projects to use.

It is now distributed as part of most non-BSD distributions.

Referenced By

arc4random.3bsd(3), bitstring.3bsd(3), byteorder.3bsd(3), closefrom.3bsd(3), errc.3bsd(3), expand_number.3bsd(3), explicit_bzero.3bsd(3), fgetln.3bsd(3), fgetwln.3bsd(3), flopen.3bsd(3), fmtcheck.3bsd(3), fparseln.3bsd(3), fpurge.3bsd(3), funopen.3bsd(3), getbsize.3bsd(3), getpeereid.3bsd(3), getprogname.3bsd(3), heapsort.3bsd(3), humanize_number.3bsd(3), md5.3bsd(3), nlist.3bsd(3), pidfile.3bsd(3), queue.3bsd(3), radixsort.3bsd(3), readpassphrase.3bsd(3), reallocarray.3bsd(3), reallocf.3bsd(3), setmode.3bsd(3), setproctitle.3bsd(3), stringlist.3bsd(3), strlcpy.3bsd(3), strmode.3bsd(3), strnstr.3bsd(3), strtonum.3bsd(3), timeradd.3bsd(3), timeval.3bsd(3), tree.3bsd(3), unvis.3bsd(3), vis.3bsd(3), wcslcpy.3bsd(3).

May 31 2017