1libbsd(7)            BSD Miscellaneous Information Manual            libbsd(7)
2

NAME

4     libbsd — utility functions from BSD systems
5

DESCRIPTION

7     The libbsd library provides a set of compatibility macros and functions
8     commonly found on BSD-based systems.  Its purpose is to make those avail‐
9     able on non-BSD based systems to ease portability.
10
11     The library can be used in an overlay mode, which is the preferred way,
12     so that the code is portable and requires no modification to the original
13     BSD code.  This can be done easily with the pkgconf(1) library named
14     libbsd-overlay.  Or by adding the system-specific include directory with
15     the bsd/ suffix to the list of system include paths.  With gcc this could
16     be -isystem ${includedir}/bsd.  In addition the LIBBSD_OVERLAY pre-pro‐
17     cessor variable needs to be defined.  The includes in this case should be
18     the usual system ones, such as <unistd.h>.
19
20     The other way to use the library is to use the namespaced headers, which
21     is a discouraged way, being less portable as it makes using libbsd manda‐
22     tory and it will not work on BSD-based systems, and requires modifying
23     original BSD code.  This can be done with the pkgconf(1) library named
24     libbsd.  The includes in this case should be namespaced with bsd/, such
25     as <bsd/unistd.h>.
26
27     The package also provides a libbsd-ctor static library that can be used
28     to inject automatic constructors into a program so that the
29     setproctitle_init(3) function gets invoked automatically at startup time.
30     This can be done with the pkgconf(1) library named libbsd-ctor.
31

HEADERS

33     The following are the headers provided by libbsd, that extend the stan‐
34     dard system headers.  They can work in normal or overlay modes, for the
35     former they need to be prefixed with bsd/.
36
37     <bitstring.h>
38     <err.h>
39     <getopt.h>
40     <grp.h>
41     <inttypes.h>
42     <libutil.h>
43     <md5.h>
44     <netinet/ip_icmp.h>
45     <nlist.h>
46     <pwd.h>
47     <readpassphrase.h>
48     <stdio.h>
49     <stdlib.h>
50     <string.h>
51     <stringlist.h>
52     <sys/bitstring.h>
53     <sys/cdefs.h>
54     <sys/endian.h>
55     <sys/param.h>
56     <sys/poll.h>
57     <sys/queue.h>
58     <sys/time.h>
59     <sys/tree.h>
60     <timeconv.h>
61     <unistd.h>
62     <vis.h>
63     <wchar.h>
64
65     The following is a libbsd specific convenience header, that includes some
66     of the extended headers.  It only works in non-overlay mode.
67
68     <bsd/bsd.h>
69

ALTERNATIVES

71     Some functions have different prototypes depending on the BSD where they
72     originated from, and these various implementations provided are se‐
73     lectable at build-time.
74
75     This is the list of functions that provide multiple implementations:
76
77     strnvis(3)
78     strnunvis(3)
79           NetBSD added strnvis(3) and strnunvis(3) but unfortunately made it
80           incompatible with the existing one in OpenBSD and Freedesktop's
81           libbsd (the former having existed for over ten years).  Despite
82           this incompatibility being reported during development (see
83           http://gnats.netbsd.org/44977) they still shipped it.  Even more
84           unfortunately FreeBSD and later MacOS picked up this incompatible
85           implementation.
86
87           Provide both implementations and default for now to the historical
88           one to avoid breakage, but we will switch to the NetBSD one in a
89           later release, which is internally consistent with the other vis(3)
90           functions and is now more widespread.  Define LIBBSD_NETBSD_VIS to
91           switch to the NetBSD one now.  Define LIBBSD_OPENBSD_VIS to keep
92           using the OpenBSD one.
93

DEPRECATED

95     Some functions have been deprecated, they will emit warnings at compile
96     time and possibly while being linked at run-time.  This might be due to
97     the functions not being portable at all to other systems, making the
98     package not buildable there; not portable in a correct or non-buggy way;
99     or because there are better more portable replacements now.
100
101     This is the list of currently deprecated macros and functions:
102
103     fgetln(3)
104           Unportable, requires assistance from the stdio layer.  An implemen‐
105           tation has to choose between leaking buffers or being reentrant for
106           a limited amount of streams (this implementation chose the latter
107           with a limit of 32).  Use getline(3) instead, which is available in
108           many systems and required by IEEE Std 1003.1-2008 (“POSIX.1”).
109
110     fgetwln(3)
111           Unportable, requires assistance from the stdio layer.  An implemen‐
112           tation has to choose between leaking buffers or being reentrant for
113           a limited amount of streams (this implementation chose the latter
114           with a limit of 32).  Use fgetwc(3) instead, which is available in
115           many systems and required by ISO/IEC 9899:1999 (“ISO C99”) and IEEE
116           Std 1003.1-2001 (“POSIX.1”).
117
118     funopen(3)
119           Unportable, requires assistance from the stdio layer or some hook
120           framework.  On GNU systems the fopencookie(3) function can be used.
121           Otherwise the code needs to be prepared for neither of these func‐
122           tions being available.
123

SUPERSEDED

125     Some functions have been superseded by implementations in other system
126     libraries, and might disappear on the next SONAME bump, assuming those
127     other implementation have widespread deployment, or the implementations
128     are present in all major libc for example.
129
130     MD5Init(3)
131     MD5Update(3)
132     MD5Pad(3)
133     MD5Final(3)
134     MD5Transform(3)
135     MD5End(3)
136     MD5File(3)
137     MD5FileChunk(3)
138     MD5Data(3)
139           The set of MD5 digest functions are now proxies for the implementa‐
140           tions provided by the libmd companion library, so it is advised to
141           switch to use that directly instead.
142     explicit_bzero(3)
143           This function is provided by glibc 2.25, and musl 1.1.20.
144     reallocarray(3)
145           This function is provided by glibc 2.26, and musl 1.2.2.
146     arc4random(3)
147     arc4random_buf(3)
148     arc4random_uniform(3)
149           These functions are provided by glibc 2.36.  Note that it does not
150           provide the arc4random_stir(3) and arc4random_addrandom(3) func‐
151           tions.
152

SEE ALSO

154     arc4random(3bsd), bitstring(3bsd), byteorder(3bsd), closefrom(3bsd),
155     errc(3bsd), expand_number(3bsd), explicit_bzero(3bsd), fgetln(3bsd),
156     fgetwln(3bsd), flopen(3bsd), fmtcheck(3bsd), fparseln(3bsd),
157     fpurge(3bsd), funopen(3bsd), getbsize(3bsd), getpeereid(3bsd),
158     getprogname(3bsd), heapsort(3bsd), humanize_number(3bsd), md5(3bsd),
159     nlist(3bsd), pidfile(3bsd), pwcache(3bsd), queue(3bsd), radixsort(3bsd),
160     readpassphrase(3bsd), reallocarray(3bsd), reallocf(3bsd), setmode(3bsd),
161     setproctitle(3bsd), stringlist(3bsd), strlcpy(3bsd), strmode(3bsd),
162     strnstr(3bsd), strtoi(3bsd), strtonum(3bsd), strtou(3bsd),
163     timeradd(3bsd), timeval(3bsd), tree(3bsd), unvis(3bsd), vis(3bsd),
164     wcslcpy(3bsd).
165

HISTORY

167     The libbsd project started in the Debian GNU/kFreeBSD port as a way to
168     ease porting code from FreeBSD to the GNU-based system.  Pretty early on
169     it was generalized and a project created on FreeDesktop.org for other
170     distributions and projects to use.
171
172     It is now distributed as part of most non-BSD distributions.
173
174BSD                             August 3, 2022                             BSD
Impressum