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 if 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 pkg-config(3) 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, this
21     is less portable as it makes using libbsd mandatory and it will not work
22     on BSD-based systems, and requires modifying original BSD code.  This can
23     be done with the pkg-config(3) library named libbsd.  The includes in
24     this case should be namespaced with bsd/, such as <bsd/unistd.h>.
25
26     The package also provides a bsd-ctor static library that can be used to
27     inject automatic constructors into a program so that the setproctitle()
28     function gets invoked automatically at startup time.  This can be done
29     with the pkg-config(3) library named libbsd-ctor.
30

HEADERS

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

DEPRECATED

67     Some functions have been deprecated, they will emit warnings at compile
68     time and possibly while being linked at run-time.  This might be due to
69     the functions not being portable at all to other systems, making the
70     package not buildable there; not portable in a correct or non-buggy way;
71     or because there are better more portable replacements now.
72
73     This is the list of currently deprecated macros and functions:
74
75     fgetln()
76           Unportable, requires assistance from the stdio layer.  An implemen‐
77           tation has to choose between leaking buffers or being reentrant for
78           a limited amount of streams (this implementation chose the latter
79           with a limit of 32).  Use getline(3) instead, which is available in
80           many systems and required by IEEE Std 1003.1-2008 (“POSIX.1”).
81
82     fgetwln()
83           Unportable, requires assistance from the stdio layer.  An implemen‐
84           tation has to choose between leaking buffers or being reentrant for
85           a limited amount of streams (this implementation chose the latter
86           with a limit of 32).  Use fgetwc(3) instead, which is available in
87           many systems and required by ISO/IEC 9899:1999 (“ISO C99”) and IEEE
88           Std 1003.1-2001 (“POSIX.1”).
89
90     funopen()
91           Unportable, requires assistance from the stdio layer or some hook
92           framework.  On GNU systems the fopencookie() function can be used.
93           Otherwise the code needs to be prepared for neither of these func‐
94           tions being available.
95

SUPERSEDED

97     Some functions have been superseded by implementations in other system
98     libraries, and might disappear on the next SONAME bump, assuming those
99     other implementation have widespread deployment, or the implementations
100     are present in all major libc for example.
101
102     MD5Init()
103     MD5Update()
104     MD5Pad()
105     MD5Final()
106     MD5Transform()
107     MD5End()
108     MD5File()
109     MD5FileChunk()
110     MD5Data()
111           The set of MD5 digest functions are now provided by the libmd com‐
112           panion library, so it is advised to use that instead.
113     explicit_bzero()
114           This function is provided by glibc 2.25.
115     reallocarray()
116           This function is provided by glibc 2.26.
117

SEE ALSO

119     arc4random(3bsd), bitstring(3bsd), byteorder(3bsd), closefrom(3bsd),
120     errc(3bsd), expand_number(3bsd), explicit_bzero(3bsd), fgetln(3bsd),
121     fgetwln(3bsd), flopen(3bsd), fmtcheck(3bsd), fparseln(3bsd),
122     fpurge(3bsd), funopen(3bsd), getbsize(3bsd), getpeereid(3bsd),
123     getprogname(3bsd), heapsort(3bsd), humanize_number(3bsd), md5(3bsd),
124     nlist(3bsd), pidfile(3bsd), queue(3bsd), radixsort(3bsd),
125     readpassphrase(3bsd), reallocarray(3bsd), reallocf(3bsd), setmode(3bsd),
126     setproctitle(3bsd), stringlist(3bsd), strlcpy(3bsd), strmode(3bsd),
127     strnstr(3bsd), strtoi(3bsd), strtonum(3bsd), strtou(3bsd),
128     timeradd(3bsd), timeval(3bsd), tree(3bsd), unvis(3bsd), vis(3bsd),
129     wcslcpy(3bsd).
130

HISTORY

132     The libbsd project started in the Debian GNU/kFreeBSD port as a way to
133     ease porting code from FreeBSD to the GNU-based system.  Pretty early on
134     it was generalized and a project created on FreeDesktop.org for other
135     distributions and projects to use.
136
137     It is now distributed as part of most non-BSD distributions.
138
139BSD                               May 21 2018                              BSD
Impressum