www.LinuxHowtos.org





libbsd

Section: Environments, Tables, and Troff Macros (7)
Index Return to Main Contents

BSD mandoc
 

NAME

libbsd - utility functions from BSD systems  

DESCRIPTION

The libbsd library provides a set of compatibility macros and functions commonly found on BS-based systems. Its purpose is to make those available on no-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 pkgconf(1) library named libbs-overlay Or by adding the syste-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 pr-processor variable needs to be defined. The includes in this case should be the usual system ones, such as In unistd.h .

The other way to use the library is to use the namespaced headers, which is a discouraged way, being less portable as it makes using libbsd mandatory and it will not work on BS-based systems, and requires modifying original BSD code. This can be done with the pkgconf(1) library named libbsd The includes in this case should be namespaced with bsd/ such as In bsd/unistd.h .

The package also provides a libbs-ctor static library that can be used to inject automatic constructors into a program so that the setproctitle_init3 function gets invoked automatically at startup time. This can be done with the pkgconf(1) library named libbs-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/

In bitstring.h
In err.h
In getopt.h
In grp.h
In inttypes.h
In libutil.h
In md5.h
In netinet/ip_icmp.h
In nlist.h
In pwd.h
In readpassphrase.h
In stdio.h
In stdlib.h
In string.h
In stringlist.h
In sys/bitstring.h
In sys/cdefs.h
In sys/endian.h
In sys/param.h
In sys/poll.h
In sys/queue.h
In sys/time.h
In sys/tree.h
In timeconv.h
In unistd.h
In vis.h
In wchar.h

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

In bsd/bsd.h

 

VARIANTS

Some functions have different prototypes depending on the BSD where they originated from, and these various implementations provided are selectable at buil-time.

This is the list of functions that provide multiple implementations:

Fn strnvis 3
Fn strnunvis 3
Nx added strnvis(3) and strnunvis(3) but unfortunately made it incompatible with the existing one in Ox and Freedesktop's libbsd (the former having existed for over ten years). Despite this incompatibility being reported during development (see http://gnats.netbsd.org/44977) they still shipped it. Even more unfortunately Fx and later MacOS picked up this incompatible implementation.

Provide both implementations and default for now to the historical one to avoid breakage, but we will switch to the Nx one in a later release, which is internally consistent with the other vis(3) functions and is now more widespread. Define LIBBSD_NETBSD_VIS to switch to the Nx one now. Define LIBBSD_OPENBSD_VIS to keep using the Ox one.

 

DEPRECATED

Some functions have been deprecated, they will emit warnings at compile time and possibly while being linked at ru-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 no-buggy way; or because there are better more portable replacements now.

This is the list of currently deprecated macros and functions:

Fn fgetln 3
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 St -p1003.-2008 .
Fn fgetwln 3
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 fgetwc(3) instead, which is available in many systems and required by St -iso-99 and St -p1003.-2001 .
Fn funopen 3
Unportable, requires assistance from the stdio layer or some hook framework. On GNU systems the fopencookie(3) function can be used. Otherwise the code needs to be prepared for neither of these functions being available.

 

SUPERSEDED

Some functions have been superseded by implementations in other system libraries, and might disappear on the next SONAME bump, assuming those other implementation have widespread deployment, or the implementations are present in all major libc for example.

Fn MD5Init 3
Fn MD5Update 3
Fn MD5Pad 3
Fn MD5Final 3
Fn MD5Transform 3
Fn MD5End 3
Fn MD5File 3
Fn MD5FileChunk 3
Fn MD5Data 3
The set of MD5 digest functions are now proxies for the implementations provided by the libmd companion library, so it is advised to switch to use that directly instead.
Fn explicit_bzero 3
This function is provided by glibc 2.25, and musl 1.1.20.
Fn reallocarray 3
This function is provided by glibc 2.26, and musl 1.2.2.
arc4random(3)
arc4random_buf3
arc4random_uniform3
These functions are provided by glibc 2.36. Note that it does not provide the arc4random_stir3 and arc4random_addrandom3 functions.

 

SEE ALSO

arc4random(3bsd), bitstring(3bsd), byteorder(3bsd), closefrom(3bsd), errc(3bsd), expand_number3bsd, explicit_bzero3bsd, fgetln(3bsd), fgetwln(3bsd), flopen(3bsd), fmtcheck(3bsd), fparseln(3bsd), fpurge(3bsd), funopen(3bsd), getbsize(3bsd), getpeereid(3bsd), getprogname(3bsd), heapsort(3bsd), humanize_number3bsd, md5(3bsd), nlist(3bsd), pidfile(3bsd), pwcache(3bsd), queue(3bsd), radixsort(3bsd), readpassphrase(3bsd), reallocarray(3bsd), reallocf(3bsd), setmode(3bsd), setproctitle(3bsd), stringlist(3bsd), strlcpy(3bsd), strmode(3bsd), strnstr(3bsd), strtoi(3bsd), strtonum(3bsd), strtou(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 GN-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 no-BSD distributions.


 

Index

NAME
DESCRIPTION
HEADERS
VARIANTS
DEPRECATED
SUPERSEDED
SEE ALSO
HISTORY