libbsd: Branch 'master' - 37 commits

Guillem Jover guillem at kemper.freedesktop.org
Mon May 28 23:18:04 PDT 2012


 .gitignore                 |   13 
 COPYING                    |  144 ++++++
 Makefile                   |  237 ----------
 Makefile.am                |   19 
 Versions                   |   91 ---
 autogen                    |    5 
 configure.ac               |   78 +++
 get-version                |    3 
 include/Makefile.am        |   24 +
 include/bsd/bitstring.h    |   32 +
 include/bsd/bsd.h          |    7 
 include/bsd/cdefs.h        |   42 -
 include/bsd/err.h          |   14 
 include/bsd/getopt.h       |    8 
 include/bsd/inet.h         |   38 -
 include/bsd/ip_icmp.h      |   42 -
 include/bsd/libutil.h      |    2 
 include/bsd/nlist.h        |    2 
 include/bsd/queue.h        |   42 -
 include/bsd/random.h       |   42 -
 include/bsd/stdio.h        |   14 
 include/bsd/stdlib.h       |   25 -
 include/bsd/string.h       |   21 
 include/bsd/sys/cdefs.h    |    8 
 include/bsd/sys/endian.h   |  144 ++++++
 include/bsd/sys/poll.h     |    8 
 include/bsd/unistd.h       |   16 
 include/libutil.h          |   38 -
 include/nlist.h            |   38 -
 include/vis.h              |   38 -
 libbsd-overlay.pc.in       |   11 
 libbsd.pc.in               |   11 
 man/.gitignore             |    2 
 man/Makefile.am            |   53 ++
 man/arc4random.3           |  128 +++++
 man/arc4random_addrandom.3 |    1 
 man/arc4random_buf.3       |    1 
 man/arc4random_stir.3      |    1 
 man/arc4random_uniform.3   |    1 
 man/bitstring.3            |  186 ++++++++
 man/closefrom.3            |   54 ++
 man/dehumanize_number.3    |    1 
 man/expand_number.3        |   87 +++
 man/fgetln.3               |  125 +++++
 man/flopen.3               |  102 ++++
 man/fmtcheck.3             |  111 ++++
 man/getmode.3              |    1 
 man/getpeereid.3           |  138 +++++
 man/getprogname.3          |   95 ++++
 man/heapsort.3             |  208 +++++++++
 man/humanize_number.3      |  171 +++++++
 man/mdX.3bsd               |  226 +++++++++
 man/mergesort.3            |    1 
 man/nlist.3                |   78 +++
 man/pidfile.3              |  254 ++++++++++
 man/queue.3bsd             | 1040 +++++++++++++++++++++++++++++++++++++++++++++
 man/radixsort.3            |  161 ++++++
 man/readpassphrase.3       |  168 +++++++
 man/reallocf.3             |  107 ++++
 man/setmode.3              |  115 ++++
 man/setproctitle.3         |  124 +++++
 man/setprogname.3          |    1 
 man/sradixsort.3           |    1 
 man/strlcat.3              |    1 
 man/strlcpy.3              |  191 ++++++++
 man/strmode.3              |  145 ++++++
 man/strtonum.3             |  159 ++++++
 man/tree.3                 |  504 +++++++++++++++++++++
 man/unvis.3                |  198 ++++++++
 man/vis.3                  |  321 +++++++++++++
 src/.gitignore             |    2 
 src/Makefile.am            |   88 +++
 src/arc4random.3           |  128 -----
 src/arc4random_addrandom.3 |    1 
 src/arc4random_buf.3       |    1 
 src/arc4random_stir.3      |    1 
 src/arc4random_uniform.3   |    1 
 src/closefrom.c            |  122 +++++
 src/dehumanize_number.3    |    1 
 src/err.c                  |   13 
 src/expand_number.c        |  101 ++++
 src/fgetln.3               |  125 -----
 src/fgetln.c               |    4 
 src/flopen.3               |  102 ----
 src/fmtcheck.3             |  111 ----
 src/fpurge.c               |    6 
 src/getmode.3              |    1 
 src/getpeereid.3           |  138 -----
 src/getpeereid.c           |    2 
 src/hash/md5.c             |    2 
 src/heapsort.3             |  208 ---------
 src/heapsort.c             |    2 
 src/humanize_number.3      |  171 -------
 src/libbsd-overlay.pc.in   |   11 
 src/libbsd.map             |   96 ++++
 src/libbsd.pc.in           |   11 
 src/local-elf.h            |    2 
 src/mdX.3                  |  226 ---------
 src/mergesort.3            |    1 
 src/nlist.3                |   78 ---
 src/nlist.c                |    6 
 src/pidfile.3              |  254 ----------
 src/pidfile.c              |    2 
 src/progname.c             |   12 
 src/radixsort.3            |  161 ------
 src/readpassphrase.3       |  168 -------
 src/reallocf.3             |  107 ----
 src/setmode.3              |  115 ----
 src/setproctitle.c         |    2 
 src/sradixsort.3           |    1 
 src/strlcat.3              |    1 
 src/strlcpy.3              |  191 --------
 src/strmode.3              |  145 ------
 src/strtonum.3             |  159 ------
 src/unvis.3                |  198 --------
 src/vis.3                  |  321 -------------
 test/.gitignore            |    3 
 test/Makefile.am           |   19 
 test/endian.c              |   68 ++
 test/headers.c             |   25 +
 test/overlay.c             |   23 
 121 files changed, 6358 insertions(+), 3897 deletions(-)

New commits:
commit 309c82a016d5cfc84d71066f21edc7cd7f5ab95d
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue May 29 04:38:07 2012 +0200

    Release libbsd 0.4.0

diff --git a/src/Makefile.am b/src/Makefile.am
index d0f07e0..ec56b93 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,7 +37,7 @@ libbsd_la_DEPENDENCIES = \
 	libbsd.map
 libbsd_la_LDFLAGS = \
 	-Wl,--version-script=$(srcdir)/libbsd.map \
-	-version-number 0:3:0
+	-version-number 0:4:0
 libbsd_la_SOURCES = \
 	arc4random.c \
 	bsd_getopt.c \
commit cd67cb14173b4329d4cb8c74ea88240e5e4bf2c3
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue May 29 07:17:46 2012 +0200

    Use implicit <md5.h> from overlay instead explicit <bsd/md5.h>
    
    This was assuming an installed <bsd/md5.h> on the system, due to the
    build system not including -Iinclude/ anymore.
    
    Regression introduced in commit 901ed630fc64fca828e031bc8fa6780db9f05db1.

diff --git a/src/Makefile.am b/src/Makefile.am
index 61d7119..d0f07e0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,7 +31,7 @@ lib_LTLIBRARIES = libbsd.la
 
 hash/md5hl.c: $(srcdir)/hash/helper.c
 	$(MKDIR_P) hash
-	$(AM_V_GEN) sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
+	$(AM_V_GEN) sed -e 's:hashinc:md5.h:g' -e 's:HASH:MD5:g' $< > $@
 
 libbsd_la_DEPENDENCIES = \
 	libbsd.map
diff --git a/src/hash/md5.c b/src/hash/md5.c
index 697183b..e60bbd9 100644
--- a/src/hash/md5.c
+++ b/src/hash/md5.c
@@ -19,7 +19,7 @@
 
 #include <sys/types.h>
 #include <string.h>
-#include <bsd/md5.h>
+#include <md5.h>
 
 #define PUT_64BIT_LE(cp, value) do {					\
 	(cp)[7] = (value) >> 56;					\
commit 1b5b1cd52ab0209d6213f02ba62fbb959d534fd2
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Apr 24 04:20:58 2012 +0200

    Move mdX.3 man page to section 3bsd
    
    This makes sure there will be no collisions on systems where a mdX.3
    provided by a third party is already present.

diff --git a/man/Makefile.am b/man/Makefile.am
index e7e69c4..16d3cb0 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in
 
 EXTRA_DIST = \
-	mdX.3 \
+	mdX.3bsd \
 	$(nil)
 
 CLEANFILES = \
@@ -10,7 +10,7 @@ CLEANFILES = \
 
 SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
 
-md5.3bsd: $(srcdir)/mdX.3
+md5.3bsd: $(srcdir)/mdX.3bsd
 	$(AM_V_GEN) sed $(SED_MD5_SUBST) $< > $@
 
 dist_man_MANS = \
diff --git a/man/mdX.3 b/man/mdX.3
deleted file mode 100644
index 41bf329..0000000
--- a/man/mdX.3
+++ /dev/null
@@ -1,226 +0,0 @@
-.\"
-.\" ----------------------------------------------------------------------------
-.\" "THE BEER-WARE LICENSE" (Revision 42):
-.\" <phk at login.dkuug.dk> wrote this file.  As long as you retain this notice you
-.\" can do whatever you want with this stuff. If we meet some day, and you think
-.\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
-.\" ----------------------------------------------------------------------------
-.\"
-.\" 	$MirOS: src/lib/libc/hash/mdX.3,v 1.4 2007/05/07 16:15:56 tg Exp $
-.\" 	$OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $
-.\"
-.Dd April 29, 2004
-.Dt MDX 3
-.Os
-.Sh NAME
-.Nm MDXInit ,
-.Nm MDXUpdate ,
-.Nm MDXPad ,
-.Nm MDXFinal ,
-.Nm MDXTransform ,
-.Nm MDXEnd ,
-.Nm MDXFile ,
-.Nm MDXFileChunk ,
-.Nm MDXData
-.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.Fd #include <sys/types.h>
-.Fd #include <bsd/mdX.h>
-.Ft void
-.Fn MDXInit "MDX_CTX *context"
-.Ft void
-.Fn MDXUpdate "MDX_CTX *context" "const u_int8_t *data" "size_t len"
-.Ft void
-.Fn MDXPad "MDX_CTX *context"
-.Ft void
-.Fn MDXFinal "u_int8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context"
-.Ft void
-.Fn MDXTransform "u_int32_t state[4]" "u_int8_t block[MDX_BLOCK_LENGTH]"
-.Ft "char *"
-.Fn MDXEnd "MDX_CTX *context" "char *buf"
-.Ft "char *"
-.Fn MDXFile "const char *filename" "char *buf"
-.Ft "char *"
-.Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
-.Ft "char *"
-.Fn MDXData "const u_int8_t *data" "size_t len" "char *buf"
-.Sh DESCRIPTION
-The MDX functions calculate a 128-bit cryptographic checksum (digest)
-for any number of input bytes.
-A cryptographic checksum is a one-way
-hash-function, that is, you cannot find (except by exhaustive search)
-the input corresponding to a particular output.
-This net result is a
-.Dq fingerprint
-of the input-data, which doesn't disclose the actual input.
-.Pp
-MD4 has been broken; it should only be used where necessary for
-backward compatibility.
-MD5 has not yet (1999-02-11) been broken, but recent attacks have cast
-some doubt on its security properties.
-The attacks on both MD4 and MD5
-are both in the nature of finding
-.Dq collisions
-\- that is, multiple
-inputs which hash to the same value; it is still unlikely for an attacker
-to be able to determine the exact original input given a hash value.
-.Pp
-The
-.Fn MDXInit ,
-.Fn MDXUpdate ,
-and
-.Fn MDXFinal
-functions are the core functions.
-Allocate an MDX_CTX, initialize it with
-.Fn MDXInit ,
-run over the data with
-.Fn MDXUpdate ,
-and finally extract the result using
-.Fn MDXFinal .
-.Pp
-The
-.Fn MDXPad
-function can be used to apply padding to the message digest as in
-.Fn MDXFinal ,
-but the current context can still be used with
-.Fn MDXUpdate .
-.Pp
-The
-.Fn MDXTransform
-function is used by
-.Fn MDXUpdate
-to hash 512-bit blocks and forms the core of the algorithm.
-Most programs should use the interface provided by
-.Fn MDXInit ,
-.Fn MDXUpdate
-and
-.Fn MDXFinal
-instead of calling
-.Fn MDXTransform
-directly.
-.Pp
-.Fn MDXEnd
-is a wrapper for
-.Fn MDXFinal
-which converts the return value to an MDX_DIGEST_STRING_LENGTH-character
-(including the terminating '\e0')
-.Tn ASCII
-string which represents the 128 bits in hexadecimal.
-.Pp
-.Fn MDXFile
-calculates the digest of a file, and uses
-.Fn MDXEnd
-to return the result.
-If the file cannot be opened, a null pointer is returned.
-.Pp
-.Fn MDXFileChunk
-behaves like
-.Fn MDXFile
-but calculates the digest only for that portion of the file starting at
-.Fa offset
-and continuing for
-.Fa length
-bytes or until end of file is reached, whichever comes first.
-A zero
-.Fa length
-can be specified to read until end of file.
-A negative
-.Fa length
-or
-.Fa offset
-will be ignored.
-.Fn MDXData
-calculates the digest of a chunk of data in memory, and uses
-.Fn MDXEnd
-to return the result.
-.Pp
-When using
-.Fn MDXEnd ,
-.Fn MDXFile ,
-.Fn MDXFileChunk ,
-or
-.Fn MDXData ,
-the
-.Ar buf
-argument can be a null pointer, in which case the returned string
-is allocated with
-.Xr malloc 3
-and subsequently must be explicitly deallocated using
-.Xr free 3
-after use.
-If the
-.Ar buf
-argument is non-null it must point to at least MDX_DIGEST_STRING_LENGTH
-characters of buffer space.
-.Sh SEE ALSO
-.Xr cksum 1 ,
-.Xr md5 1 ,
-.Xr adler32 3 ,
-.Xr mdY 3 ,
-.Xr rmd160 3 ,
-.Xr sfv 3 ,
-.Xr sha1 3 ,
-.Xr sha2 3 ,
-.Xr suma 3 ,
-.Xr tiger 3 ,
-.Xr whirlpool 3
-.Rs
-.%A R. Rivest
-.%T The MD4 Message-Digest Algorithm
-.%O RFC 1186
-.Re
-.Rs
-.%A R. Rivest
-.%T The MD5 Message-Digest Algorithm
-.%O RFC 1321
-.Re
-.Rs
-.%A RSA Laboratories
-.%T Frequently Asked Questions About today's Cryptography
-.%O \&<http://www.rsa.com/rsalabs/faq/>
-.Re
-.Rs
-.%A H. Dobbertin
-.%T Alf Swindles Ann
-.%J CryptoBytes
-.%N 1(3):5
-.%D 1995
-.Re
-.Rs
-.%A MJ. B. Robshaw
-.%T On Recent Results for MD4 and MD5
-.%J RSA Laboratories Bulletin
-.%N 4
-.%D November 12, 1996
-.Re
-.Rs
-.%A Hans Dobbertin
-.%T Cryptanalysis of MD5 Compress
-.Re
-.Sh HISTORY
-These functions appeared in
-.Ox 2.0 .
-.Sh AUTHORS
-The original MDX routines were developed by
-.Tn RSA
-Data Security, Inc., and published in the above references.
-This code is derived from a public domain implementation written by Colin Plumb.
-.Pp
-The
-.Fn MDXEnd ,
-.Fn MDXFile ,
-.Fn MDXFileChunk ,
-and
-.Fn MDXData
-helper functions are derived from code written by Poul-Henning Kamp.
-.Sh BUGS
-Collisions have been found for the full versions of both MD4 and MD5
-as well as strong attacks against the SHA-0 and SHA-1 family.
-The use of
-.Xr sha2 3 ,
-or
-.Xr rmd160 3
-is recommended instead.
diff --git a/man/mdX.3bsd b/man/mdX.3bsd
new file mode 100644
index 0000000..8e1b64a
--- /dev/null
+++ b/man/mdX.3bsd
@@ -0,0 +1,226 @@
+.\"
+.\" ----------------------------------------------------------------------------
+.\" "THE BEER-WARE LICENSE" (Revision 42):
+.\" <phk at login.dkuug.dk> wrote this file.  As long as you retain this notice you
+.\" can do whatever you want with this stuff. If we meet some day, and you think
+.\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+.\" ----------------------------------------------------------------------------
+.\"
+.\" 	$MirOS: src/lib/libc/hash/mdX.3,v 1.4 2007/05/07 16:15:56 tg Exp $
+.\" 	$OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $
+.\"
+.Dd April 29, 2004
+.Dt MDX 3bsd
+.Os
+.Sh NAME
+.Nm MDXInit ,
+.Nm MDXUpdate ,
+.Nm MDXPad ,
+.Nm MDXFinal ,
+.Nm MDXTransform ,
+.Nm MDXEnd ,
+.Nm MDXFile ,
+.Nm MDXFileChunk ,
+.Nm MDXData
+.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <bsd/mdX.h>
+.Ft void
+.Fn MDXInit "MDX_CTX *context"
+.Ft void
+.Fn MDXUpdate "MDX_CTX *context" "const u_int8_t *data" "size_t len"
+.Ft void
+.Fn MDXPad "MDX_CTX *context"
+.Ft void
+.Fn MDXFinal "u_int8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context"
+.Ft void
+.Fn MDXTransform "u_int32_t state[4]" "u_int8_t block[MDX_BLOCK_LENGTH]"
+.Ft "char *"
+.Fn MDXEnd "MDX_CTX *context" "char *buf"
+.Ft "char *"
+.Fn MDXFile "const char *filename" "char *buf"
+.Ft "char *"
+.Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
+.Ft "char *"
+.Fn MDXData "const u_int8_t *data" "size_t len" "char *buf"
+.Sh DESCRIPTION
+The MDX functions calculate a 128-bit cryptographic checksum (digest)
+for any number of input bytes.
+A cryptographic checksum is a one-way
+hash-function, that is, you cannot find (except by exhaustive search)
+the input corresponding to a particular output.
+This net result is a
+.Dq fingerprint
+of the input-data, which doesn't disclose the actual input.
+.Pp
+MD4 has been broken; it should only be used where necessary for
+backward compatibility.
+MD5 has not yet (1999-02-11) been broken, but recent attacks have cast
+some doubt on its security properties.
+The attacks on both MD4 and MD5
+are both in the nature of finding
+.Dq collisions
+\- that is, multiple
+inputs which hash to the same value; it is still unlikely for an attacker
+to be able to determine the exact original input given a hash value.
+.Pp
+The
+.Fn MDXInit ,
+.Fn MDXUpdate ,
+and
+.Fn MDXFinal
+functions are the core functions.
+Allocate an MDX_CTX, initialize it with
+.Fn MDXInit ,
+run over the data with
+.Fn MDXUpdate ,
+and finally extract the result using
+.Fn MDXFinal .
+.Pp
+The
+.Fn MDXPad
+function can be used to apply padding to the message digest as in
+.Fn MDXFinal ,
+but the current context can still be used with
+.Fn MDXUpdate .
+.Pp
+The
+.Fn MDXTransform
+function is used by
+.Fn MDXUpdate
+to hash 512-bit blocks and forms the core of the algorithm.
+Most programs should use the interface provided by
+.Fn MDXInit ,
+.Fn MDXUpdate
+and
+.Fn MDXFinal
+instead of calling
+.Fn MDXTransform
+directly.
+.Pp
+.Fn MDXEnd
+is a wrapper for
+.Fn MDXFinal
+which converts the return value to an MDX_DIGEST_STRING_LENGTH-character
+(including the terminating '\e0')
+.Tn ASCII
+string which represents the 128 bits in hexadecimal.
+.Pp
+.Fn MDXFile
+calculates the digest of a file, and uses
+.Fn MDXEnd
+to return the result.
+If the file cannot be opened, a null pointer is returned.
+.Pp
+.Fn MDXFileChunk
+behaves like
+.Fn MDXFile
+but calculates the digest only for that portion of the file starting at
+.Fa offset
+and continuing for
+.Fa length
+bytes or until end of file is reached, whichever comes first.
+A zero
+.Fa length
+can be specified to read until end of file.
+A negative
+.Fa length
+or
+.Fa offset
+will be ignored.
+.Fn MDXData
+calculates the digest of a chunk of data in memory, and uses
+.Fn MDXEnd
+to return the result.
+.Pp
+When using
+.Fn MDXEnd ,
+.Fn MDXFile ,
+.Fn MDXFileChunk ,
+or
+.Fn MDXData ,
+the
+.Ar buf
+argument can be a null pointer, in which case the returned string
+is allocated with
+.Xr malloc 3
+and subsequently must be explicitly deallocated using
+.Xr free 3
+after use.
+If the
+.Ar buf
+argument is non-null it must point to at least MDX_DIGEST_STRING_LENGTH
+characters of buffer space.
+.Sh SEE ALSO
+.Xr cksum 1 ,
+.Xr md5 1 ,
+.Xr adler32 3 ,
+.Xr mdY 3 ,
+.Xr rmd160 3 ,
+.Xr sfv 3 ,
+.Xr sha1 3 ,
+.Xr sha2 3 ,
+.Xr suma 3 ,
+.Xr tiger 3 ,
+.Xr whirlpool 3
+.Rs
+.%A R. Rivest
+.%T The MD4 Message-Digest Algorithm
+.%O RFC 1186
+.Re
+.Rs
+.%A R. Rivest
+.%T The MD5 Message-Digest Algorithm
+.%O RFC 1321
+.Re
+.Rs
+.%A RSA Laboratories
+.%T Frequently Asked Questions About today's Cryptography
+.%O \&<http://www.rsa.com/rsalabs/faq/>
+.Re
+.Rs
+.%A H. Dobbertin
+.%T Alf Swindles Ann
+.%J CryptoBytes
+.%N 1(3):5
+.%D 1995
+.Re
+.Rs
+.%A MJ. B. Robshaw
+.%T On Recent Results for MD4 and MD5
+.%J RSA Laboratories Bulletin
+.%N 4
+.%D November 12, 1996
+.Re
+.Rs
+.%A Hans Dobbertin
+.%T Cryptanalysis of MD5 Compress
+.Re
+.Sh HISTORY
+These functions appeared in
+.Ox 2.0 .
+.Sh AUTHORS
+The original MDX routines were developed by
+.Tn RSA
+Data Security, Inc., and published in the above references.
+This code is derived from a public domain implementation written by Colin Plumb.
+.Pp
+The
+.Fn MDXEnd ,
+.Fn MDXFile ,
+.Fn MDXFileChunk ,
+and
+.Fn MDXData
+helper functions are derived from code written by Poul-Henning Kamp.
+.Sh BUGS
+Collisions have been found for the full versions of both MD4 and MD5
+as well as strong attacks against the SHA-0 and SHA-1 family.
+The use of
+.Xr sha2 3 ,
+or
+.Xr rmd160 3
+is recommended instead.
commit ddefaae330f95d89cd1046bdde43d51fd0783c1b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Apr 24 04:05:48 2012 +0200

    Do not quote man page titles

diff --git a/man/flopen.3 b/man/flopen.3
index 8f81211..97a6260 100644
--- a/man/flopen.3
+++ b/man/flopen.3
@@ -30,7 +30,7 @@
 .Os
 .Sh NAME
 .Nm flopen
-.Nd "Reliably open and lock a file"
+.Nd reliably open and lock a file
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
 .Lb libbsd
diff --git a/man/pidfile.3 b/man/pidfile.3
index 2f84c44..7b2697d 100644
--- a/man/pidfile.3
+++ b/man/pidfile.3
@@ -32,7 +32,7 @@
 .Nm pidfile_write ,
 .Nm pidfile_close ,
 .Nm pidfile_remove
-.Nd "library for PID files handling"
+.Nd library for PID files handling
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
 .Lb libbsd
diff --git a/man/strtonum.3 b/man/strtonum.3
index 42674f0..f159a23 100644
--- a/man/strtonum.3
+++ b/man/strtonum.3
@@ -20,7 +20,7 @@
 .Os
 .Sh NAME
 .Nm strtonum
-.Nd "reliably convert string value to an integer"
+.Nd reliably convert string value to an integer
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
 .Lb libbsd
diff --git a/man/tree.3 b/man/tree.3
index 68e28dc..07cf0aa 100644
--- a/man/tree.3
+++ b/man/tree.3
@@ -74,7 +74,7 @@
 .Nm RB_INIT ,
 .Nm RB_INSERT ,
 .Nm RB_REMOVE
-.Nd "implementations of splay and red-black trees"
+.Nd implementations of splay and red-black trees
 .Sh SYNOPSIS
 .In bsd/sys/tree.h
 .Fn SPLAY_PROTOTYPE NAME TYPE FIELD CMP
commit e7f3976088b038687e54a2df09cb9e3332af42df
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Mar 23 10:31:42 2012 +0100

    Add email address to my name

diff --git a/COPYING b/COPYING
index dd472c4..1a4fdce 100644
--- a/COPYING
+++ b/COPYING
@@ -66,7 +66,7 @@ for man/arc4random.3, man/tree.3 and man/getprogname.3.
 The rest of the licenses apply to code and/or man pages.
 
 
-    Copyright © 2004-2006, 2008-2011 Guillem Jover
+    Copyright © 2004-2006, 2008-2011 Guillem Jover <guillem at hadrons.org>
     Copyright © 2005 Hector Garcia Alvarez
     Copyright © 2005 Aurelien Jarno
     Copyright © 2006 Robert Millan
diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h
index b46056a..c246a91 100644
--- a/include/bsd/bsd.h
+++ b/include/bsd/bsd.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2004, 2005, 2006 Guillem Jover
+ * Copyright © 2004, 2005, 2006 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/err.h b/include/bsd/err.h
index 11d1250..fcaaa85 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2006 Robert Millan
- * Copyright © 2009, 2011 Guillem Jover
+ * Copyright © 2009, 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index 9fb2e7e..a6505e9 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2011 Guillem Jover
+ * Copyright © 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/nlist.h b/include/bsd/nlist.h
index 310748f..2730237 100644
--- a/include/bsd/nlist.h
+++ b/include/bsd/nlist.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2009 Guillem Jover
+ * Copyright © 2009 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/stdio.h b/include/bsd/stdio.h
index 22e9d2c..62d587f 100644
--- a/include/bsd/stdio.h
+++ b/include/bsd/stdio.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2004, 2005, 2009, 2011 Guillem Jover
+ * Copyright © 2004, 2005, 2009, 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 5448011..dd30703 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2005 Aurelien Jarno
  * Copyright © 2006 Robert Millan
- * Copyright © 2008-2011 Guillem Jover
+ * Copyright © 2008-2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/string.h b/include/bsd/string.h
index ac2a5a5..f385947 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2004, 2005, 2009, 2011 Guillem Jover
+ * Copyright © 2004, 2005, 2009, 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index 49bbeb5..c08d68d 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2004-2006, 2009-2011 Guillem Jover
+ * Copyright © 2004-2006, 2009-2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/sys/endian.h b/include/bsd/sys/endian.h
index 58fca50..6ddf715 100644
--- a/include/bsd/sys/endian.h
+++ b/include/bsd/sys/endian.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2011 Guillem Jover
+ * Copyright © 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/sys/poll.h b/include/bsd/sys/poll.h
index 0e34103..455efa4 100644
--- a/include/bsd/sys/poll.h
+++ b/include/bsd/sys/poll.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2011 Guillem Jover
+ * Copyright © 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index e576b89..193dd35 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2006 Robert Millan
- * Copyright © 2008-2011 Guillem Jover
+ * Copyright © 2008-2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/src/fgetln.c b/src/fgetln.c
index 87bd2e9..183e853 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2005 Hector Garcia Alvarez
- * Copyright © 2005, 2008, 2009, 2011 Guillem Jover
+ * Copyright © 2005, 2008, 2009, 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/src/fpurge.c b/src/fpurge.c
index e2483f2..e31b84a 100644
--- a/src/fpurge.c
+++ b/src/fpurge.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2011 Guillem Jover
+ * Copyright © 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/src/getpeereid.c b/src/getpeereid.c
index 8990357..3694219 100644
--- a/src/getpeereid.c
+++ b/src/getpeereid.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2010 Guillem Jover
+ * Copyright © 2010 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/src/local-elf.h b/src/local-elf.h
index 0c06c49..afcc8ed 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2009 Guillem Jover
+ * Copyright © 2009 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/src/setproctitle.c b/src/setproctitle.c
index 0cf36ef..239fb01 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2010 Guillem Jover
+ * Copyright © 2010 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
commit e59ac2c96c4f9299912868cd86fa650639050f78
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Mar 23 10:11:57 2012 +0100

    Clarify that the 4-clause BSD licenses are only for man pages

diff --git a/COPYING b/COPYING
index c3e05ae..dd472c4 100644
--- a/COPYING
+++ b/COPYING
@@ -1,3 +1,7 @@
+The following 4-clause BSD licenses are only for man pages, specifically
+for man/arc4random.3, man/tree.3 and man/getprogname.3.
+
+
     Copyright 1997 Niels Provos <provos at physnet.uni-hamburg.de>
     All rights reserved.
 
@@ -58,7 +62,9 @@
     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-    --
+
+The rest of the licenses apply to code and/or man pages.
+
 
     Copyright © 2004-2006, 2008-2011 Guillem Jover
     Copyright © 2005 Hector Garcia Alvarez
commit 7cfa7e4304756151b7987a62fb304300f1205a42
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jan 12 19:13:16 2012 +0100

    Add new man page for tree(3)
    
    Taken from FreeBSD.

diff --git a/man/Makefile.am b/man/Makefile.am
index 3a50703..e7e69c4 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -47,6 +47,7 @@ dist_man_MANS = \
 	strlcpy.3 \
 	strmode.3 \
 	strtonum.3 \
+	tree.3 \
 	unvis.3 \
 	vis.3 \
 	$(nil)
diff --git a/man/tree.3 b/man/tree.3
new file mode 100644
index 0000000..68e28dc
--- /dev/null
+++ b/man/tree.3
@@ -0,0 +1,504 @@
+.\"	$OpenBSD: tree.3,v 1.7 2002/06/12 01:09:20 provos Exp $
+.\"
+.\" Copyright 2002 Niels Provos <provos at citi.umich.edu>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"      This product includes software developed by Niels Provos.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 27, 2007
+.Dt TREE 3
+.Os
+.Sh NAME
+.Nm SPLAY_PROTOTYPE ,
+.Nm SPLAY_GENERATE ,
+.Nm SPLAY_ENTRY ,
+.Nm SPLAY_HEAD ,
+.Nm SPLAY_INITIALIZER ,
+.Nm SPLAY_ROOT ,
+.Nm SPLAY_EMPTY ,
+.Nm SPLAY_NEXT ,
+.Nm SPLAY_MIN ,
+.Nm SPLAY_MAX ,
+.Nm SPLAY_FIND ,
+.Nm SPLAY_LEFT ,
+.Nm SPLAY_RIGHT ,
+.Nm SPLAY_FOREACH ,
+.Nm SPLAY_INIT ,
+.Nm SPLAY_INSERT ,
+.Nm SPLAY_REMOVE ,
+.Nm RB_PROTOTYPE ,
+.Nm RB_PROTOTYPE_STATIC ,
+.Nm RB_GENERATE ,
+.Nm RB_GENERATE_STATIC ,
+.Nm RB_ENTRY ,
+.Nm RB_HEAD ,
+.Nm RB_INITIALIZER ,
+.Nm RB_ROOT ,
+.Nm RB_EMPTY ,
+.Nm RB_NEXT ,
+.Nm RB_PREV ,
+.Nm RB_MIN ,
+.Nm RB_MAX ,
+.Nm RB_FIND ,
+.Nm RB_NFIND ,
+.Nm RB_LEFT ,
+.Nm RB_RIGHT ,
+.Nm RB_PARENT ,
+.Nm RB_FOREACH ,
+.Nm RB_FOREACH_REVERSE ,
+.Nm RB_INIT ,
+.Nm RB_INSERT ,
+.Nm RB_REMOVE
+.Nd "implementations of splay and red-black trees"
+.Sh SYNOPSIS
+.In bsd/sys/tree.h
+.Fn SPLAY_PROTOTYPE NAME TYPE FIELD CMP
+.Fn SPLAY_GENERATE NAME TYPE FIELD CMP
+.Fn SPLAY_ENTRY TYPE
+.Fn SPLAY_HEAD HEADNAME TYPE
+.Ft "struct TYPE *"
+.Fn SPLAY_INITIALIZER "SPLAY_HEAD *head"
+.Fn SPLAY_ROOT "SPLAY_HEAD *head"
+.Ft bool
+.Fn SPLAY_EMPTY "SPLAY_HEAD *head"
+.Ft "struct TYPE *"
+.Fn SPLAY_NEXT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn SPLAY_MIN NAME "SPLAY_HEAD *head"
+.Ft "struct TYPE *"
+.Fn SPLAY_MAX NAME "SPLAY_HEAD *head"
+.Ft "struct TYPE *"
+.Fn SPLAY_FIND NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn SPLAY_LEFT "struct TYPE *elm" "SPLAY_ENTRY NAME"
+.Ft "struct TYPE *"
+.Fn SPLAY_RIGHT "struct TYPE *elm" "SPLAY_ENTRY NAME"
+.Fn SPLAY_FOREACH VARNAME NAME "SPLAY_HEAD *head"
+.Ft void
+.Fn SPLAY_INIT "SPLAY_HEAD *head"
+.Ft "struct TYPE *"
+.Fn SPLAY_INSERT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn SPLAY_REMOVE NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Fn RB_PROTOTYPE NAME TYPE FIELD CMP
+.Fn RB_PROTOTYPE_STATIC NAME TYPE FIELD CMP
+.Fn RB_GENERATE NAME TYPE FIELD CMP
+.Fn RB_GENERATE_STATIC NAME TYPE FIELD CMP
+.Fn RB_ENTRY TYPE
+.Fn RB_HEAD HEADNAME TYPE
+.Fn RB_INITIALIZER "RB_HEAD *head"
+.Ft "struct TYPE *"
+.Fn RB_ROOT "RB_HEAD *head"
+.Ft "bool"
+.Fn RB_EMPTY "RB_HEAD *head"
+.Ft "struct TYPE *"
+.Fn RB_NEXT NAME "RB_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn RB_PREV NAME "RB_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn RB_MIN NAME "RB_HEAD *head"
+.Ft "struct TYPE *"
+.Fn RB_MAX NAME "RB_HEAD *head"
+.Ft "struct TYPE *"
+.Fn RB_FIND NAME "RB_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn RB_NFIND NAME "RB_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn RB_LEFT "struct TYPE *elm" "RB_ENTRY NAME"
+.Ft "struct TYPE *"
+.Fn RB_RIGHT "struct TYPE *elm" "RB_ENTRY NAME"
+.Ft "struct TYPE *"
+.Fn RB_PARENT "struct TYPE *elm" "RB_ENTRY NAME"
+.Fn RB_FOREACH VARNAME NAME "RB_HEAD *head"
+.Fn RB_FOREACH_REVERSE VARNAME NAME "RB_HEAD *head"
+.Ft void
+.Fn RB_INIT "RB_HEAD *head"
+.Ft "struct TYPE *"
+.Fn RB_INSERT NAME "RB_HEAD *head" "struct TYPE *elm"
+.Ft "struct TYPE *"
+.Fn RB_REMOVE NAME "RB_HEAD *head" "struct TYPE *elm"
+.Sh DESCRIPTION
+These macros define data structures for different types of trees:
+splay trees and red-black trees.
+.Pp
+In the macro definitions,
+.Fa TYPE
+is the name tag of a user defined structure that must contain a field of type
+.Vt SPLAY_ENTRY ,
+or
+.Vt RB_ENTRY ,
+named
+.Fa ENTRYNAME .
+The argument
+.Fa HEADNAME
+is the name tag of a user defined structure that must be declared
+using the macros
+.Fn SPLAY_HEAD ,
+or
+.Fn RB_HEAD .
+The argument
+.Fa NAME
+has to be a unique name prefix for every tree that is defined.
+.Pp
+The function prototypes are declared with
+.Fn SPLAY_PROTOTYPE ,
+.Fn RB_PROTOTYPE ,
+or
+.Fn RB_PROTOTYPE_STATIC .
+The function bodies are generated with
+.Fn SPLAY_GENERATE ,
+.Fn RB_GENERATE ,
+or
+.Fn RB_GENERATE_STATIC .
+See the examples below for further explanation of how these macros are used.
+.Sh SPLAY TREES
+A splay tree is a self-organizing data structure.
+Every operation on the tree causes a splay to happen.
+The splay moves the requested
+node to the root of the tree and partly rebalances it.
+.Pp
+This has the benefit that request locality causes faster lookups as
+the requested nodes move to the top of the tree.
+On the other hand, every lookup causes memory writes.
+.Pp
+The Balance Theorem bounds the total access time for
+.Ar m
+operations and
+.Ar n
+inserts on an initially empty tree as
+.Fn O "\*[lp]m + n\*[rp]lg n" .
+The
+amortized cost for a sequence of
+.Ar m
+accesses to a splay tree is
+.Fn O "lg n" .
+.Pp
+A splay tree is headed by a structure defined by the
+.Fn SPLAY_HEAD
+macro.
+A
+structure is declared as follows:
+.Bd -ragged -offset indent
+.Fn SPLAY_HEAD HEADNAME TYPE
+.Va head ;
+.Ed
+.Pp
+where
+.Fa HEADNAME
+is the name of the structure to be defined, and struct
+.Fa TYPE
+is the type of the elements to be inserted into the tree.
+.Pp
+The
+.Fn SPLAY_ENTRY
+macro declares a structure that allows elements to be connected in the tree.
+.Pp
+In order to use the functions that manipulate the tree structure,
+their prototypes need to be declared with the
+.Fn SPLAY_PROTOTYPE
+macro,
+where
+.Fa NAME
+is a unique identifier for this particular tree.
+The
+.Fa TYPE
+argument is the type of the structure that is being managed
+by the tree.
+The
+.Fa FIELD
+argument is the name of the element defined by
+.Fn SPLAY_ENTRY .
+.Pp
+The function bodies are generated with the
+.Fn SPLAY_GENERATE
+macro.
+It takes the same arguments as the
+.Fn SPLAY_PROTOTYPE
+macro, but should be used only once.
+.Pp
+Finally,
+the
+.Fa CMP
+argument is the name of a function used to compare tree nodes
+with each other.
+The function takes two arguments of type
+.Vt "struct TYPE *" .
+If the first argument is smaller than the second, the function returns a
+value smaller than zero.
+If they are equal, the function returns zero.
+Otherwise, it should return a value greater than zero.
+The compare
+function defines the order of the tree elements.
+.Pp
+The
+.Fn SPLAY_INIT
+macro initializes the tree referenced by
+.Fa head .
+.Pp
+The splay tree can also be initialized statically by using the
+.Fn SPLAY_INITIALIZER
+macro like this:
+.Bd -ragged -offset indent
+.Fn SPLAY_HEAD HEADNAME TYPE
+.Va head
+=
+.Fn SPLAY_INITIALIZER &head ;
+.Ed
+.Pp
+The
+.Fn SPLAY_INSERT
+macro inserts the new element
+.Fa elm
+into the tree.
+.Pp
+The
+.Fn SPLAY_REMOVE
+macro removes the element
+.Fa elm
+from the tree pointed by
+.Fa head .
+.Pp
+The
+.Fn SPLAY_FIND
+macro can be used to find a particular element in the tree.
+.Bd -literal -offset indent
+struct TYPE find, *res;
+find.key = 30;
+res = SPLAY_FIND(NAME, head, &find);
+.Ed
+.Pp
+The
+.Fn SPLAY_ROOT ,
+.Fn SPLAY_MIN ,
+.Fn SPLAY_MAX ,
+and
+.Fn SPLAY_NEXT
+macros can be used to traverse the tree:
+.Bd -literal -offset indent
+for (np = SPLAY_MIN(NAME, &head); np != NULL; np = SPLAY_NEXT(NAME, &head, np))
+.Ed
+.Pp
+Or, for simplicity, one can use the
+.Fn SPLAY_FOREACH
+macro:
+.Bd -ragged -offset indent
+.Fn SPLAY_FOREACH np NAME head
+.Ed
+.Pp
+The
+.Fn SPLAY_EMPTY
+macro should be used to check whether a splay tree is empty.
+.Sh RED-BLACK TREES
+A red-black tree is a binary search tree with the node color as an
+extra attribute.
+It fulfills a set of conditions:
+.Bl -enum -offset indent
+.It
+Every search path from the root to a leaf consists of the same number of
+black nodes.
+.It
+Each red node (except for the root) has a black parent.
+.It
+Each leaf node is black.
+.El
+.Pp
+Every operation on a red-black tree is bounded as
+.Fn O "lg n" .
+The maximum height of a red-black tree is
+.Fn 2lg "n + 1" .
+.Pp
+A red-black tree is headed by a structure defined by the
+.Fn RB_HEAD
+macro.
+A
+structure is declared as follows:
+.Bd -ragged -offset indent
+.Fn RB_HEAD HEADNAME TYPE
+.Va head ;
+.Ed
+.Pp
+where
+.Fa HEADNAME
+is the name of the structure to be defined, and struct
+.Fa TYPE
+is the type of the elements to be inserted into the tree.
+.Pp
+The
+.Fn RB_ENTRY
+macro declares a structure that allows elements to be connected in the tree.
+.Pp
+In order to use the functions that manipulate the tree structure,
+their prototypes need to be declared with the
+.Fn RB_PROTOTYPE
+or
+.Fn RB_PROTOTYPE_STATIC
+macro,
+where
+.Fa NAME
+is a unique identifier for this particular tree.
+The
+.Fa TYPE
+argument is the type of the structure that is being managed
+by the tree.
+The
+.Fa FIELD
+argument is the name of the element defined by
+.Fn RB_ENTRY .
+.Pp
+The function bodies are generated with the
+.Fn RB_GENERATE
+or
+.Fn RB_GENERATE_STATIC
+macro.
+These macros take the same arguments as the
+.Fn RB_PROTOTYPE
+and
+.Fn RB_PROTOTYPE_STATIC
+macros, but should be used only once.
+.Pp
+Finally,
+the
+.Fa CMP
+argument is the name of a function used to compare tree nodes
+with each other.
+The function takes two arguments of type
+.Vt "struct TYPE *" .
+If the first argument is smaller than the second, the function returns a
+value smaller than zero.
+If they are equal, the function returns zero.
+Otherwise, it should return a value greater than zero.
+The compare
+function defines the order of the tree elements.
+.Pp
+The
+.Fn RB_INIT
+macro initializes the tree referenced by
+.Fa head .
+.Pp
+The red-black tree can also be initialized statically by using the
+.Fn RB_INITIALIZER
+macro like this:
+.Bd -ragged -offset indent
+.Fn RB_HEAD HEADNAME TYPE
+.Va head
+=
+.Fn RB_INITIALIZER &head ;
+.Ed
+.Pp
+The
+.Fn RB_INSERT
+macro inserts the new element
+.Fa elm
+into the tree.
+.Pp
+The
+.Fn RB_REMOVE
+macro removes the element
+.Fa elm
+from the tree pointed by
+.Fa head .
+.Pp
+The
+.Fn RB_FIND
+and
+.Fn RB_NFIND
+macros can be used to find a particular element in the tree.
+.Bd -literal -offset indent
+struct TYPE find, *res;
+find.key = 30;
+res = RB_FIND(NAME, head, &find);
+.Ed
+.Pp
+The
+.Fn RB_ROOT ,
+.Fn RB_MIN ,
+.Fn RB_MAX ,
+.Fn RB_NEXT ,
+and
+.Fn RB_PREV
+macros can be used to traverse the tree:
+.Pp
+.Dl "for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np))"
+.Pp
+Or, for simplicity, one can use the
+.Fn RB_FOREACH
+or
+.Fn RB_FOREACH_REVERSE
+macro:
+.Bd -ragged -offset indent
+.Fn RB_FOREACH np NAME head
+.Ed
+.Pp
+The
+.Fn RB_EMPTY
+macro should be used to check whether a red-black tree is empty.
+.Sh NOTES
+Trying to free a tree in the following way is a common error:
+.Bd -literal -offset indent
+SPLAY_FOREACH(var, NAME, head) {
+	SPLAY_REMOVE(NAME, head, var);
+	free(var);
+}
+free(head);
+.Ed
+.Pp
+Since
+.Va var
+is freed, the
+.Fn FOREACH
+macro refers to a pointer that may have been reallocated already.
+Proper code needs a second variable.
+.Bd -literal -offset indent
+for (var = SPLAY_MIN(NAME, head); var != NULL; var = nxt) {
+	nxt = SPLAY_NEXT(NAME, head, var);
+	SPLAY_REMOVE(NAME, head, var);
+	free(var);
+}
+.Ed
+.Pp
+Both
+.Fn RB_INSERT
+and
+.Fn SPLAY_INSERT
+return
+.Dv NULL
+if the element was inserted in the tree successfully, otherwise they
+return a pointer to the element with the colliding key.
+.Pp
+Accordingly,
+.Fn RB_REMOVE
+and
+.Fn SPLAY_REMOVE
+return the pointer to the removed element otherwise they return
+.Dv NULL
+to indicate an error.
+.Sh SEE ALSO
+.Xr queue 3
+.Sh AUTHORS
+The author of the tree macros is
+.An Niels Provos .
commit 7620fef70bac36435dae756554f575826cb89f8b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jan 12 20:56:24 2012 +0100

    Remove UC Berkeley advertising clause
    
    As per <ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>.

diff --git a/man/bitstring.3 b/man/bitstring.3
index e721532..cd9b5bf 100644
--- a/man/bitstring.3
+++ b/man/bitstring.3
@@ -11,10 +11,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
diff --git a/man/queue.3bsd b/man/queue.3bsd
index f7a5649..fc861e7 100644
--- a/man/queue.3bsd
+++ b/man/queue.3bsd
@@ -9,10 +9,6 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
 .\" 4. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
commit 08139dd50e6b728a1d9052e852799f60a7f8482d
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jan 12 19:13:16 2012 +0100

    Add new man pages for bitstring(3) and queue(3)
    
    Taken from FreeBSD.

diff --git a/man/Makefile.am b/man/Makefile.am
index f22d201..3a50703 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -19,6 +19,7 @@ dist_man_MANS = \
 	arc4random_buf.3 \
 	arc4random_stir.3 \
 	arc4random_uniform.3 \
+	bitstring.3 \
 	closefrom.3 \
 	dehumanize_number.3 \
 	expand_number.3 \
@@ -34,6 +35,7 @@ dist_man_MANS = \
 	mergesort.3 \
 	nlist.3 \
 	pidfile.3 \
+	queue.3bsd \
 	radixsort.3 \
 	readpassphrase.3 \
 	reallocf.3 \
diff --git a/man/bitstring.3 b/man/bitstring.3
new file mode 100644
index 0000000..e721532
--- /dev/null
+++ b/man/bitstring.3
@@ -0,0 +1,190 @@
+.\" Copyright (c) 1989, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Paul Vixie.
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"	This product includes software developed by the University of
+.\"	California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)bitstring.3	8.1 (Berkeley) 7/19/93
+.\" $FreeBSD$
+.\"
+.Dd July 19, 1993
+.Dt BITSTRING 3
+.Os
+.Sh NAME
+.Nm bit_alloc ,
+.Nm bit_clear ,
+.Nm bit_decl ,
+.Nm bit_ffs ,
+.Nm bit_nclear ,
+.Nm bit_nset ,
+.Nm bit_set ,
+.Nm bitstr_size ,
+.Nm bit_test
+.Nd bit-string manipulation macros
+.Sh SYNOPSIS
+.In bsd/bitstring.h
+.Ft bitstr_t *
+.Fn bit_alloc "int nbits"
+.Ft void
+.Fn bit_decl "bitstr_t *name" "int nbits"
+.Ft void
+.Fn bit_clear "bitstr_t *name" "int bit"
+.Ft void
+.Fn bit_ffc "bitstr_t *name" "int nbits" "int *value"
+.Ft void
+.Fn bit_ffs "bitstr_t *name" "int nbits" "int *value"
+.Ft void
+.Fn bit_nclear "bitstr_t *name" "int start" "int stop"
+.Ft void
+.Fn bit_nset "bitstr_t *name" "int start" "int stop"
+.Ft void
+.Fn bit_set "bitstr_t *name" "int bit"
+.Ft int
+.Fn bitstr_size "int nbits"
+.Ft int
+.Fn bit_test "bitstr_t *name" "int bit"
+.Sh DESCRIPTION
+These macros operate on strings of bits.
+.Pp
+The macro
+.Fn bit_alloc
+returns a pointer of type
+.Dq Fa "bitstr_t *"
+to sufficient space to store
+.Fa nbits
+bits, or
+.Dv NULL
+if no space is available.
+.Pp
+The macro
+.Fn bit_decl
+allocates sufficient space to store
+.Fa nbits
+bits on the stack.
+.Pp
+The macro
+.Fn bitstr_size
+returns the number of elements of type
+.Fa bitstr_t
+necessary to store
+.Fa nbits
+bits.
+This is useful for copying bit strings.
+.Pp
+The macros
+.Fn bit_clear
+and
+.Fn bit_set
+clear or set the zero-based numbered bit
+.Fa bit ,
+in the bit string
+.Ar name .
+.Pp
+The
+.Fn bit_nset
+and
+.Fn bit_nclear
+macros
+set or clear the zero-based numbered bits from
+.Fa start
+through
+.Fa stop
+in the bit string
+.Ar name .
+.Pp
+The
+.Fn bit_test
+macro
+evaluates to non-zero if the zero-based numbered bit
+.Fa bit
+of bit string
+.Fa name
+is set, and zero otherwise.
+.Pp
+The
+.Fn bit_ffs
+macro
+stores in the location referenced by
+.Fa value
+the zero-based number of the first bit set in the array of
+.Fa nbits
+bits referenced by
+.Fa name .
+If no bits are set, the location referenced by
+.Fa value
+is set to \-1.
+.Pp
+The macro
+.Fn bit_ffc
+stores in the location referenced by
+.Fa value
+the zero-based number of the first bit not set in the array of
+.Fa nbits
+bits referenced by
+.Fa name .
+If all bits are set, the location referenced by
+.Fa value
+is set to \-1.
+.Pp
+The arguments to these macros are evaluated only once and may safely
+have side effects.
+.Sh EXAMPLES
+.Bd -literal -offset indent
+#include <limits.h>
+#include <bsd/bitstring.h>
+
+\&...
+#define	LPR_BUSY_BIT		0
+#define	LPR_FORMAT_BIT		1
+#define	LPR_DOWNLOAD_BIT	2
+\&...
+#define	LPR_AVAILABLE_BIT	9
+#define	LPR_MAX_BITS		10
+
+make_lpr_available()
+{
+	bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
+	...
+	bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
+	...
+	if (!bit_test(bitlist, LPR_BUSY_BIT)) {
+		bit_clear(bitlist, LPR_FORMAT_BIT);
+		bit_clear(bitlist, LPR_DOWNLOAD_BIT);
+		bit_set(bitlist, LPR_AVAILABLE_BIT);
+	}
+}
+.Ed
+.Sh SEE ALSO
+.Xr malloc 3
+.Sh HISTORY
+The
+.Nm bitstring
+functions first appeared in
+.Bx 4.4 .
diff --git a/man/queue.3bsd b/man/queue.3bsd
new file mode 100644
index 0000000..f7a5649
--- /dev/null
+++ b/man/queue.3bsd
@@ -0,0 +1,1044 @@
+.\" Copyright (c) 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"	This product includes software developed by the University of
+.\"	California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"	@(#)queue.3	8.2 (Berkeley) 1/24/94
+.\" $FreeBSD$
+.\"
+.Dd May 13, 2011
+.Dt QUEUE 3bsd
+.Os
+.Sh NAME
+.Nm SLIST_EMPTY ,
+.Nm SLIST_ENTRY ,
+.Nm SLIST_FIRST ,
+.Nm SLIST_FOREACH ,
+.Nm SLIST_FOREACH_SAFE ,
+.Nm SLIST_HEAD ,
+.Nm SLIST_HEAD_INITIALIZER ,
+.Nm SLIST_INIT ,
+.Nm SLIST_INSERT_AFTER ,
+.Nm SLIST_INSERT_HEAD ,
+.Nm SLIST_NEXT ,
+.Nm SLIST_REMOVE_AFTER ,
+.Nm SLIST_REMOVE_HEAD ,
+.Nm SLIST_REMOVE ,
+.Nm SLIST_SWAP ,
+.Nm STAILQ_CONCAT ,
+.Nm STAILQ_EMPTY ,
+.Nm STAILQ_ENTRY ,
+.Nm STAILQ_FIRST ,
+.Nm STAILQ_FOREACH ,
+.Nm STAILQ_FOREACH_SAFE ,
+.Nm STAILQ_HEAD ,
+.Nm STAILQ_HEAD_INITIALIZER ,
+.Nm STAILQ_INIT ,
+.Nm STAILQ_INSERT_AFTER ,
+.Nm STAILQ_INSERT_HEAD ,
+.Nm STAILQ_INSERT_TAIL ,
+.Nm STAILQ_LAST ,
+.Nm STAILQ_NEXT ,
+.Nm STAILQ_REMOVE_AFTER ,
+.Nm STAILQ_REMOVE_HEAD ,
+.Nm STAILQ_REMOVE ,
+.Nm STAILQ_SWAP ,
+.Nm LIST_EMPTY ,
+.Nm LIST_ENTRY ,
+.Nm LIST_FIRST ,
+.Nm LIST_FOREACH ,
+.Nm LIST_FOREACH_SAFE ,
+.Nm LIST_HEAD ,
+.Nm LIST_HEAD_INITIALIZER ,
+.Nm LIST_INIT ,
+.Nm LIST_INSERT_AFTER ,
+.Nm LIST_INSERT_BEFORE ,
+.Nm LIST_INSERT_HEAD ,
+.Nm LIST_NEXT ,
+.Nm LIST_REMOVE ,
+.Nm LIST_SWAP ,
+.Nm TAILQ_CONCAT ,
+.Nm TAILQ_EMPTY ,
+.Nm TAILQ_ENTRY ,
+.Nm TAILQ_FIRST ,
+.Nm TAILQ_FOREACH ,
+.Nm TAILQ_FOREACH_SAFE ,
+.Nm TAILQ_FOREACH_REVERSE ,
+.Nm TAILQ_FOREACH_REVERSE_SAFE ,
+.Nm TAILQ_HEAD ,
+.Nm TAILQ_HEAD_INITIALIZER ,
+.Nm TAILQ_INIT ,
+.Nm TAILQ_INSERT_AFTER ,
+.Nm TAILQ_INSERT_BEFORE ,
+.Nm TAILQ_INSERT_HEAD ,
+.Nm TAILQ_INSERT_TAIL ,
+.Nm TAILQ_LAST ,
+.Nm TAILQ_NEXT ,
+.Nm TAILQ_PREV ,
+.Nm TAILQ_REMOVE ,
+.Nm TAILQ_SWAP
+.Nd implementations of singly-linked lists, singly-linked tail queues,
+lists and tail queues
+.Sh SYNOPSIS
+.In bsd/sys/queue.h
+.\"
+.Fn SLIST_EMPTY "SLIST_HEAD *head"
+.Fn SLIST_ENTRY "TYPE"
+.Fn SLIST_FIRST "SLIST_HEAD *head"
+.Fn SLIST_FOREACH "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME"
+.Fn SLIST_FOREACH_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var"
+.Fn SLIST_HEAD "HEADNAME" "TYPE"
+.Fn SLIST_HEAD_INITIALIZER "SLIST_HEAD head"
+.Fn SLIST_INIT "SLIST_HEAD *head"
+.Fn SLIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "SLIST_ENTRY NAME"
+.Fn SLIST_INSERT_HEAD "SLIST_HEAD *head" "TYPE *elm" "SLIST_ENTRY NAME"
+.Fn SLIST_NEXT "TYPE *elm" "SLIST_ENTRY NAME"
+.Fn SLIST_REMOVE_AFTER "TYPE *elm" "SLIST_ENTRY NAME"
+.Fn SLIST_REMOVE_HEAD "SLIST_HEAD *head" "SLIST_ENTRY NAME"
+.Fn SLIST_REMOVE "SLIST_HEAD *head" "TYPE *elm" "TYPE" "SLIST_ENTRY NAME"
+.Fn SLIST_SWAP "SLIST_HEAD *head1" "SLIST_HEAD *head2" "SLIST_ENTRY NAME"
+.\"
+.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
+.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
+.Fn STAILQ_ENTRY "TYPE"
+.Fn STAILQ_FIRST "STAILQ_HEAD *head"
+.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
+.Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
+.Fn STAILQ_HEAD "HEADNAME" "TYPE"
+.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
+.Fn STAILQ_INIT "STAILQ_HEAD *head"
+.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME"
+.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
+.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME"
+.Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
+.\"
+.Fn LIST_EMPTY "LIST_HEAD *head"
+.Fn LIST_ENTRY "TYPE"
+.Fn LIST_FIRST "LIST_HEAD *head"
+.Fn LIST_FOREACH "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME"
+.Fn LIST_FOREACH_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var"
+.Fn LIST_HEAD "HEADNAME" "TYPE"
+.Fn LIST_HEAD_INITIALIZER "LIST_HEAD head"
+.Fn LIST_INIT "LIST_HEAD *head"
+.Fn LIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME"
+.Fn LIST_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME"
+.Fn LIST_INSERT_HEAD "LIST_HEAD *head" "TYPE *elm" "LIST_ENTRY NAME"
+.Fn LIST_NEXT "TYPE *elm" "LIST_ENTRY NAME"
+.Fn LIST_REMOVE "TYPE *elm" "LIST_ENTRY NAME"
+.Fn LIST_SWAP "LIST_HEAD *head1" "LIST_HEAD *head2" "TYPE" "LIST_ENTRY NAME"
+.\"
+.Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TAILQ_ENTRY NAME"
+.Fn TAILQ_EMPTY "TAILQ_HEAD *head"
+.Fn TAILQ_ENTRY "TYPE"
+.Fn TAILQ_FIRST "TAILQ_HEAD *head"
+.Fn TAILQ_FOREACH "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME"
+.Fn TAILQ_FOREACH_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var"
+.Fn TAILQ_FOREACH_REVERSE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME"
+.Fn TAILQ_FOREACH_REVERSE_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var"
+.Fn TAILQ_HEAD "HEADNAME" "TYPE"
+.Fn TAILQ_HEAD_INITIALIZER "TAILQ_HEAD head"
+.Fn TAILQ_INIT "TAILQ_HEAD *head"
+.Fn TAILQ_INSERT_AFTER "TAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "TAILQ_ENTRY NAME"
+.Fn TAILQ_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "TAILQ_ENTRY NAME"
+.Fn TAILQ_INSERT_HEAD "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME"
+.Fn TAILQ_INSERT_TAIL "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME"
+.Fn TAILQ_LAST "TAILQ_HEAD *head" "HEADNAME"
+.Fn TAILQ_NEXT "TYPE *elm" "TAILQ_ENTRY NAME"
+.Fn TAILQ_PREV "TYPE *elm" "HEADNAME" "TAILQ_ENTRY NAME"
+.Fn TAILQ_REMOVE "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME"
+.Fn TAILQ_SWAP "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TYPE" "TAILQ_ENTRY NAME"
+.\"
+.Sh DESCRIPTION
+These macros define and operate on four types of data structures:
+singly-linked lists, singly-linked tail queues, lists, and tail queues.
+All four structures support the following functionality:
+.Bl -enum -compact -offset indent
+.It
+Insertion of a new entry at the head of the list.
+.It
+Insertion of a new entry after any element in the list.
+.It
+O(1) removal of an entry from the head of the list.
+.It
+Forward traversal through the list.
+.It
+Swapping the contents of two lists.
+.El
+.Pp
+Singly-linked lists are the simplest of the four data structures
+and support only the above functionality.
+Singly-linked lists are ideal for applications with large datasets
+and few or no removals,
+or for implementing a LIFO queue.
+Singly-linked lists add the following functionality:
+.Bl -enum -compact -offset indent
+.It
+O(n) removal of any entry in the list.
+.El
+.Pp
+Singly-linked tail queues add the following functionality:
+.Bl -enum -compact -offset indent
+.It
+Entries can be added at the end of a list.
+.It
+O(n) removal of any entry in the list.
+.It
+They may be concatenated.
+.El
+However:
+.Bl -enum -compact -offset indent
+.It
+All list insertions must specify the head of the list.
+.It
+Each head entry requires two pointers rather than one.
+.It
+Code size is about 15% greater and operations run about 20% slower
+than singly-linked lists.
+.El
+.Pp
+Singly-linked tail queues are ideal for applications with large datasets and
+few or no removals,
+or for implementing a FIFO queue.
+.Pp
+All doubly linked types of data structures (lists and tail queues)
+additionally allow:
+.Bl -enum -compact -offset indent
+.It
+Insertion of a new entry before any element in the list.
+.It
+O(1) removal of any entry in the list.
+.El
+However:
+.Bl -enum -compact -offset indent
+.It
+Each element requires two pointers rather than one.
+.It
+Code size and execution time of operations (except for removal) is about
+twice that of the singly-linked data-structures.
+.El
+.Pp
+Linked lists are the simplest of the doubly linked data structures and support
+only the above functionality over singly-linked lists.
+.Pp
+Tail queues add the following functionality:
+.Bl -enum -compact -offset indent
+.It
+Entries can be added at the end of a list.
+.It
+They may be traversed backwards, from tail to head.
+.It
+They may be concatenated.
+.El
+However:
+.Bl -enum -compact -offset indent
+.It
+All list insertions and removals must specify the head of the list.
+.It
+Each head entry requires two pointers rather than one.
+.It
+Code size is about 15% greater and operations run about 20% slower
+than singly-linked lists.
+.El
+.Pp
+In the macro definitions,
+.Fa TYPE
+is the name of a user defined structure,
+that must contain a field of type
+.Li SLIST_ENTRY ,
+.Li STAILQ_ENTRY ,
+.Li LIST_ENTRY ,
+or
+.Li TAILQ_ENTRY ,
+named
+.Fa NAME .
+The argument
+.Fa HEADNAME
+is the name of a user defined structure that must be declared
+using the macros
+.Li SLIST_HEAD ,
+.Li STAILQ_HEAD ,
+.Li LIST_HEAD ,
+or
+.Li TAILQ_HEAD .
+See the examples below for further explanation of how these
+macros are used.
+.Sh SINGLY-LINKED LISTS
+A singly-linked list is headed by a structure defined by the
+.Nm SLIST_HEAD
+macro.
+This structure contains a single pointer to the first element
+on the list.
+The elements are singly linked for minimum space and pointer manipulation
+overhead at the expense of O(n) removal for arbitrary elements.
+New elements can be added to the list after an existing element or
+at the head of the list.
+An
+.Fa SLIST_HEAD
+structure is declared as follows:
+.Bd -literal -offset indent
+SLIST_HEAD(HEADNAME, TYPE) head;
+.Ed
+.Pp
+where
+.Fa HEADNAME
+is the name of the structure to be defined, and
+.Fa TYPE
+is the type of the elements to be linked into the list.
+A pointer to the head of the list can later be declared as:
+.Bd -literal -offset indent
+struct HEADNAME *headp;
+.Ed
+.Pp
+(The names
+.Li head
+and
+.Li headp
+are user selectable.)
+.Pp
+The macro
+.Nm SLIST_HEAD_INITIALIZER
+evaluates to an initializer for the list
+.Fa head .
+.Pp
+The macro
+.Nm SLIST_EMPTY
+evaluates to true if there are no elements in the list.
+.Pp
+The macro
+.Nm SLIST_ENTRY
+declares a structure that connects the elements in
+the list.
+.Pp
+The macro
+.Nm SLIST_FIRST
+returns the first element in the list or NULL if the list is empty.
+.Pp
+The macro
+.Nm SLIST_FOREACH
+traverses the list referenced by
+.Fa head
+in the forward direction, assigning each element in
+turn to
+.Fa var .
+.Pp
+The macro
+.Nm SLIST_FOREACH_SAFE
+traverses the list referenced by
+.Fa head
+in the forward direction, assigning each element in
+turn to
+.Fa var .
+However, unlike
+.Fn SLIST_FOREACH
+here it is permitted to both remove
+.Fa var
+as well as free it from within the loop safely without interfering with the
+traversal.
+.Pp
+The macro
+.Nm SLIST_INIT
+initializes the list referenced by
+.Fa head .
+.Pp
+The macro
+.Nm SLIST_INSERT_HEAD
+inserts the new element
+.Fa elm
+at the head of the list.
+.Pp
+The macro
+.Nm SLIST_INSERT_AFTER
+inserts the new element
+.Fa elm
+after the element
+.Fa listelm .
+.Pp
+The macro
+.Nm SLIST_NEXT
+returns the next element in the list.
+.Pp
+The macro
+.Nm SLIST_REMOVE_AFTER
+removes the element after
+.Fa elm
+from the list. Unlike
+.Fa SLIST_REMOVE ,
+this macro does not traverse the entire list.
+.Pp
+The macro
+.Nm SLIST_REMOVE_HEAD
+removes the element
+.Fa elm
+from the head of the list.
+For optimum efficiency,
+elements being removed from the head of the list should explicitly use
+this macro instead of the generic
+.Fa SLIST_REMOVE
+macro.
+.Pp
+The macro
+.Nm SLIST_REMOVE
+removes the element
+.Fa elm
+from the list.
+.Pp
+The macro
+.Nm SLIST_SWAP
+swaps the contents of
+.Fa head1
+and
+.Fa head2 .
+.Sh SINGLY-LINKED LIST EXAMPLE
+.Bd -literal
+SLIST_HEAD(slisthead, entry) head =
+    SLIST_HEAD_INITIALIZER(head);
+struct slisthead *headp;		/* Singly-linked List head. */
+struct entry {
+	...
+	SLIST_ENTRY(entry) entries;	/* Singly-linked List. */
+	...
+} *n1, *n2, *n3, *np;
+
+SLIST_INIT(&head);			/* Initialize the list. */
+
+n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+SLIST_INSERT_HEAD(&head, n1, entries);
+
+n2 = malloc(sizeof(struct entry));	/* Insert after. */
+SLIST_INSERT_AFTER(n1, n2, entries);
+
+SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */
+free(n2);
+
+n3 = SLIST_FIRST(&head);
+SLIST_REMOVE_HEAD(&head, entries);	/* Deletion from the head. */
+free(n3);
+					/* Forward traversal. */
+SLIST_FOREACH(np, &head, entries)
+	np-> ...
+					/* Safe forward traversal. */
+SLIST_FOREACH_SAFE(np, &head, entries, np_temp) {
+	np->do_stuff();
+	...
+	SLIST_REMOVE(&head, np, entry, entries);
+	free(np);
+}
+
+while (!SLIST_EMPTY(&head)) {		/* List Deletion. */
+	n1 = SLIST_FIRST(&head);
+	SLIST_REMOVE_HEAD(&head, entries);
+	free(n1);
+}
+.Ed
+.Sh SINGLY-LINKED TAIL QUEUES
+A singly-linked tail queue is headed by a structure defined by the
+.Nm STAILQ_HEAD
+macro.
+This structure contains a pair of pointers,
+one to the first element in the tail queue and the other to
+the last element in the tail queue.
+The elements are singly linked for minimum space and pointer
+manipulation overhead at the expense of O(n) removal for arbitrary
+elements.
+New elements can be added to the tail queue after an existing element,
+at the head of the tail queue, or at the end of the tail queue.
+A
+.Fa STAILQ_HEAD
+structure is declared as follows:
+.Bd -literal -offset indent
+STAILQ_HEAD(HEADNAME, TYPE) head;
+.Ed
+.Pp
+where
+.Li HEADNAME
+is the name of the structure to be defined, and
+.Li TYPE
+is the type of the elements to be linked into the tail queue.
+A pointer to the head of the tail queue can later be declared as:
+.Bd -literal -offset indent
+struct HEADNAME *headp;
+.Ed
+.Pp
+(The names
+.Li head
+and
+.Li headp
+are user selectable.)
+.Pp
+The macro
+.Nm STAILQ_HEAD_INITIALIZER
+evaluates to an initializer for the tail queue
+.Fa head .
+.Pp
+The macro
+.Nm STAILQ_CONCAT
+concatenates the tail queue headed by
+.Fa head2
+onto the end of the one headed by
+.Fa head1
+removing all entries from the former.
+.Pp
+The macro
+.Nm STAILQ_EMPTY
+evaluates to true if there are no items on the tail queue.
+.Pp
+The macro
+.Nm STAILQ_ENTRY
+declares a structure that connects the elements in
+the tail queue.
+.Pp
+The macro
+.Nm STAILQ_FIRST
+returns the first item on the tail queue or NULL if the tail queue
+is empty.
+.Pp
+The macro
+.Nm STAILQ_FOREACH
+traverses the tail queue referenced by
+.Fa head
+in the forward direction, assigning each element
+in turn to
+.Fa var .
+.Pp
+The macro
+.Nm STAILQ_FOREACH_SAFE
+traverses the tail queue referenced by
+.Fa head
+in the forward direction, assigning each element
+in turn to
+.Fa var .
+However, unlike
+.Fn STAILQ_FOREACH
+here it is permitted to both remove
+.Fa var
+as well as free it from within the loop safely without interfering with the
+traversal.
+.Pp
+The macro
+.Nm STAILQ_INIT
+initializes the tail queue referenced by
+.Fa head .
+.Pp
+The macro
+.Nm STAILQ_INSERT_HEAD
+inserts the new element
+.Fa elm
+at the head of the tail queue.
+.Pp
+The macro
+.Nm STAILQ_INSERT_TAIL
+inserts the new element
+.Fa elm
+at the end of the tail queue.
+.Pp
+The macro
+.Nm STAILQ_INSERT_AFTER
+inserts the new element
+.Fa elm
+after the element
+.Fa listelm .
+.Pp
+The macro
+.Nm STAILQ_LAST
+returns the last item on the tail queue.
+If the tail queue is empty the return value is
+.Dv NULL .
+.Pp
+The macro
+.Nm STAILQ_NEXT
+returns the next item on the tail queue, or NULL this item is the last.
+.Pp
+The macro
+.Nm STAILQ_REMOVE_AFTER
+removes the element after
+.Fa elm
+from the tail queue. Unlike
+.Fa STAILQ_REMOVE ,
+this macro does not traverse the entire tail queue.
+.Pp
+The macro
+.Nm STAILQ_REMOVE_HEAD
+removes the element at the head of the tail queue.
+For optimum efficiency,
+elements being removed from the head of the tail queue should
+use this macro explicitly rather than the generic
+.Fa STAILQ_REMOVE
+macro.
+.Pp
+The macro
+.Nm STAILQ_REMOVE
+removes the element
+.Fa elm
+from the tail queue.
+.Pp
+The macro
+.Nm STAILQ_SWAP
+swaps the contents of
+.Fa head1
+and
+.Fa head2 .
+.Sh SINGLY-LINKED TAIL QUEUE EXAMPLE
+.Bd -literal
+STAILQ_HEAD(stailhead, entry) head =
+    STAILQ_HEAD_INITIALIZER(head);
+struct stailhead *headp;		/* Singly-linked tail queue head. */
+struct entry {
+	...
+	STAILQ_ENTRY(entry) entries;	/* Tail queue. */
+	...
+} *n1, *n2, *n3, *np;
+
+STAILQ_INIT(&head);			/* Initialize the queue. */
+
+n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+STAILQ_INSERT_HEAD(&head, n1, entries);
+
+n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+STAILQ_INSERT_TAIL(&head, n1, entries);
+
+n2 = malloc(sizeof(struct entry));	/* Insert after. */
+STAILQ_INSERT_AFTER(&head, n1, n2, entries);
+					/* Deletion. */
+STAILQ_REMOVE(&head, n2, entry, entries);
+free(n2);
+					/* Deletion from the head. */
+n3 = STAILQ_FIRST(&head);
+STAILQ_REMOVE_HEAD(&head, entries);
+free(n3);
+					/* Forward traversal. */
+STAILQ_FOREACH(np, &head, entries)
+	np-> ...
+					/* Safe forward traversal. */
+STAILQ_FOREACH_SAFE(np, &head, entries, np_temp) {
+	np->do_stuff();
+	...
+	STAILQ_REMOVE(&head, np, entry, entries);
+	free(np);
+}
+					/* TailQ Deletion. */
+while (!STAILQ_EMPTY(&head)) {
+	n1 = STAILQ_FIRST(&head);
+	STAILQ_REMOVE_HEAD(&head, entries);
+	free(n1);
+}
+					/* Faster TailQ Deletion. */
+n1 = STAILQ_FIRST(&head);
+while (n1 != NULL) {
+	n2 = STAILQ_NEXT(n1, entries);
+	free(n1);
+	n1 = n2;
+}
+STAILQ_INIT(&head);
+.Ed
+.Sh LISTS
+A list is headed by a structure defined by the
+.Nm LIST_HEAD
+macro.
+This structure contains a single pointer to the first element
+on the list.
+The elements are doubly linked so that an arbitrary element can be
+removed without traversing the list.
+New elements can be added to the list after an existing element,
+before an existing element, or at the head of the list.
+A
+.Fa LIST_HEAD
+structure is declared as follows:
+.Bd -literal -offset indent
+LIST_HEAD(HEADNAME, TYPE) head;
+.Ed
+.Pp
+where
+.Fa HEADNAME
+is the name of the structure to be defined, and
+.Fa TYPE
+is the type of the elements to be linked into the list.
+A pointer to the head of the list can later be declared as:
+.Bd -literal -offset indent
+struct HEADNAME *headp;
+.Ed
+.Pp
+(The names
+.Li head
+and
+.Li headp
+are user selectable.)
+.Pp
+The macro
+.Nm LIST_HEAD_INITIALIZER
+evaluates to an initializer for the list
+.Fa head .
+.Pp
+The macro
+.Nm LIST_EMPTY
+evaluates to true if there are no elements in the list.
+.Pp
+The macro
+.Nm LIST_ENTRY
+declares a structure that connects the elements in
+the list.
+.Pp
+The macro
+.Nm LIST_FIRST
+returns the first element in the list or NULL if the list
+is empty.
+.Pp
+The macro
+.Nm LIST_FOREACH
+traverses the list referenced by
+.Fa head
+in the forward direction, assigning each element in turn to
+.Fa var .
+.Pp
+The macro
+.Nm LIST_FOREACH_SAFE
+traverses the list referenced by
+.Fa head
+in the forward direction, assigning each element in turn to
+.Fa var .
+However, unlike
+.Fn LIST_FOREACH
+here it is permitted to both remove
+.Fa var
+as well as free it from within the loop safely without interfering with the
+traversal.
+.Pp
+The macro
+.Nm LIST_INIT
+initializes the list referenced by
+.Fa head .
+.Pp
+The macro
+.Nm LIST_INSERT_HEAD
+inserts the new element
+.Fa elm
+at the head of the list.
+.Pp
+The macro
+.Nm LIST_INSERT_AFTER
+inserts the new element
+.Fa elm
+after the element
+.Fa listelm .
+.Pp
+The macro
+.Nm LIST_INSERT_BEFORE
+inserts the new element
+.Fa elm
+before the element
+.Fa listelm .
+.Pp
+The macro
+.Nm LIST_NEXT
+returns the next element in the list, or NULL if this is the last.
+.Pp
+The macro
+.Nm LIST_REMOVE
+removes the element
+.Fa elm
+from the list.
+.Pp
+The macro
+.Nm LIST_SWAP
+swaps the contents of
+.Fa head1
+and
+.Fa head2 .
+.Sh LIST EXAMPLE
+.Bd -literal
+LIST_HEAD(listhead, entry) head =
+    LIST_HEAD_INITIALIZER(head);
+struct listhead *headp;			/* List head. */
+struct entry {
+	...
+	LIST_ENTRY(entry) entries;	/* List. */
+	...
+} *n1, *n2, *n3, *np, *np_temp;
+
+LIST_INIT(&head);			/* Initialize the list. */
+
+n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+LIST_INSERT_HEAD(&head, n1, entries);
+
+n2 = malloc(sizeof(struct entry));	/* Insert after. */
+LIST_INSERT_AFTER(n1, n2, entries);
+
+n3 = malloc(sizeof(struct entry));	/* Insert before. */
+LIST_INSERT_BEFORE(n2, n3, entries);
+
+LIST_REMOVE(n2, entries);		/* Deletion. */
+free(n2);
+					/* Forward traversal. */
+LIST_FOREACH(np, &head, entries)
+	np-> ...
+
+					/* Safe forward traversal. */
+LIST_FOREACH_SAFE(np, &head, entries, np_temp) {
+	np->do_stuff();
+	...
+	LIST_REMOVE(np, entries);
+	free(np);
+}
+
+while (!LIST_EMPTY(&head)) {		/* List Deletion. */
+	n1 = LIST_FIRST(&head);
+	LIST_REMOVE(n1, entries);
+	free(n1);
+}
+
+n1 = LIST_FIRST(&head);			/* Faster List Deletion. */
+while (n1 != NULL) {
+	n2 = LIST_NEXT(n1, entries);
+	free(n1);
+	n1 = n2;
+}
+LIST_INIT(&head);
+.Ed
+.Sh TAIL QUEUES
+A tail queue is headed by a structure defined by the
+.Nm TAILQ_HEAD
+macro.
+This structure contains a pair of pointers,
+one to the first element in the tail queue and the other to
+the last element in the tail queue.
+The elements are doubly linked so that an arbitrary element can be
+removed without traversing the tail queue.
+New elements can be added to the tail queue after an existing element,
+before an existing element, at the head of the tail queue,
+or at the end of the tail queue.
+A
+.Fa TAILQ_HEAD
+structure is declared as follows:
+.Bd -literal -offset indent
+TAILQ_HEAD(HEADNAME, TYPE) head;
+.Ed
+.Pp
+where
+.Li HEADNAME
+is the name of the structure to be defined, and
+.Li TYPE
+is the type of the elements to be linked into the tail queue.
+A pointer to the head of the tail queue can later be declared as:
+.Bd -literal -offset indent
+struct HEADNAME *headp;
+.Ed
+.Pp
+(The names
+.Li head
+and
+.Li headp
+are user selectable.)
+.Pp
+The macro
+.Nm TAILQ_HEAD_INITIALIZER
+evaluates to an initializer for the tail queue
+.Fa head .
+.Pp
+The macro
+.Nm TAILQ_CONCAT
+concatenates the tail queue headed by
+.Fa head2
+onto the end of the one headed by
+.Fa head1
+removing all entries from the former.
+.Pp
+The macro
+.Nm TAILQ_EMPTY
+evaluates to true if there are no items on the tail queue.
+.Pp
+The macro
+.Nm TAILQ_ENTRY
+declares a structure that connects the elements in
+the tail queue.
+.Pp
+The macro
+.Nm TAILQ_FIRST
+returns the first item on the tail queue or NULL if the tail queue
+is empty.
+.Pp
+The macro
+.Nm TAILQ_FOREACH
+traverses the tail queue referenced by
+.Fa head
+in the forward direction, assigning each element in turn to
+.Fa var .
+.Fa var
+is set to
+.Dv NULL
+if the loop completes normally, or if there were no elements.
+.Pp
+The macro
+.Nm TAILQ_FOREACH_REVERSE
+traverses the tail queue referenced by
+.Fa head
+in the reverse direction, assigning each element in turn to
+.Fa var .
+.Pp
+The macros
+.Nm TAILQ_FOREACH_SAFE
+and
+.Nm TAILQ_FOREACH_REVERSE_SAFE
+traverse the list referenced by
+.Fa head
+in the forward or reverse direction respectively,
+assigning each element in turn to
+.Fa var .
+However, unlike their unsafe counterparts,
+.Nm TAILQ_FOREACH
+and
+.Nm TAILQ_FOREACH_REVERSE
+permit to both remove
+.Fa var
+as well as free it from within the loop safely without interfering with the
+traversal.
+.Pp
+The macro
+.Nm TAILQ_INIT
+initializes the tail queue referenced by
+.Fa head .
+.Pp
+The macro
+.Nm TAILQ_INSERT_HEAD
+inserts the new element
+.Fa elm
+at the head of the tail queue.
+.Pp
+The macro
+.Nm TAILQ_INSERT_TAIL
+inserts the new element
+.Fa elm
+at the end of the tail queue.
+.Pp
+The macro
+.Nm TAILQ_INSERT_AFTER
+inserts the new element
+.Fa elm
+after the element
+.Fa listelm .
+.Pp
+The macro
+.Nm TAILQ_INSERT_BEFORE
+inserts the new element
+.Fa elm
+before the element
+.Fa listelm .
+.Pp
+The macro
+.Nm TAILQ_LAST
+returns the last item on the tail queue.
+If the tail queue is empty the return value is
+.Dv NULL .
+.Pp
+The macro
+.Nm TAILQ_NEXT
+returns the next item on the tail queue, or NULL if this item is the last.
+.Pp
+The macro
+.Nm TAILQ_PREV
+returns the previous item on the tail queue, or NULL if this item
+is the first.
+.Pp
+The macro
+.Nm TAILQ_REMOVE
+removes the element
+.Fa elm
+from the tail queue.
+.Pp
+The macro
+.Nm TAILQ_SWAP
+swaps the contents of
+.Fa head1
+and
+.Fa head2 .
+.Sh TAIL QUEUE EXAMPLE
+.Bd -literal
+TAILQ_HEAD(tailhead, entry) head =
+    TAILQ_HEAD_INITIALIZER(head);
+struct tailhead *headp;			/* Tail queue head. */
+struct entry {
+	...
+	TAILQ_ENTRY(entry) entries;	/* Tail queue. */
+	...
+} *n1, *n2, *n3, *np;
+
+TAILQ_INIT(&head);			/* Initialize the queue. */
+
+n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+TAILQ_INSERT_HEAD(&head, n1, entries);
+
+n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+TAILQ_INSERT_TAIL(&head, n1, entries);
+
+n2 = malloc(sizeof(struct entry));	/* Insert after. */
+TAILQ_INSERT_AFTER(&head, n1, n2, entries);
+
+n3 = malloc(sizeof(struct entry));	/* Insert before. */
+TAILQ_INSERT_BEFORE(n2, n3, entries);
+
+TAILQ_REMOVE(&head, n2, entries);	/* Deletion. */
+free(n2);
+					/* Forward traversal. */
+TAILQ_FOREACH(np, &head, entries)
+	np-> ...
+					/* Safe forward traversal. */
+TAILQ_FOREACH_SAFE(np, &head, entries, np_temp) {
+	np->do_stuff();
+	...
+	TAILQ_REMOVE(&head, np, entries);
+	free(np);
+}
+					/* Reverse traversal. */
+TAILQ_FOREACH_REVERSE(np, &head, tailhead, entries)
+	np-> ...
+					/* TailQ Deletion. */
+while (!TAILQ_EMPTY(&head)) {
+	n1 = TAILQ_FIRST(&head);
+	TAILQ_REMOVE(&head, n1, entries);
+	free(n1);
+}
+					/* Faster TailQ Deletion. */
+n1 = TAILQ_FIRST(&head);
+while (n1 != NULL) {
+	n2 = TAILQ_NEXT(n1, entries);
+	free(n1);
+	n1 = n2;
+}
+TAILQ_INIT(&head);
+.Ed
+.Sh SEE ALSO
+.Xr tree 3
+.Sh HISTORY
+The
+.Nm queue
+functions first appeared in
+.Bx 4.4 .
commit d90ce079f727a8595dbc953e62dbc119e3914c53
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat May 14 14:18:57 2011 +0200

    Add new man pages for getprogname(3) and setprogname(3)
    
    Taken from FreeBSD.

diff --git a/COPYING b/COPYING
index 57ba600..c3e05ae 100644
--- a/COPYING
+++ b/COPYING
@@ -28,6 +28,38 @@
 
     --
 
+    Copyright © 2001 Christopher G. Demetriou
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions
+    are met:
+    1. Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the distribution.
+    3. All advertising materials mentioning features or use of this software
+       must display the following acknowledgement:
+             This product includes software developed for the
+             NetBSD Project.  See http://www.netbsd.org/ for
+             information about NetBSD.
+    4. The name of the author may not be used to endorse or promote products
+       derived from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+    --
+
     Copyright © 2004-2006, 2008-2011 Guillem Jover
     Copyright © 2005 Hector Garcia Alvarez
     Copyright © 2005 Aurelien Jarno
diff --git a/man/Makefile.am b/man/Makefile.am
index d0f2271..f22d201 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -27,6 +27,7 @@ dist_man_MANS = \
 	fmtcheck.3 \
 	getmode.3 \
 	getpeereid.3 \
+	getprogname.3 \
 	heapsort.3 \
 	humanize_number.3 \
 	md5.3bsd \
@@ -38,6 +39,7 @@ dist_man_MANS = \
 	reallocf.3 \
 	setmode.3 \
 	setproctitle.3 \
+	setprogname.3 \
 	sradixsort.3 \
 	strlcat.3 \
 	strlcpy.3 \
diff --git a/man/getprogname.3 b/man/getprogname.3
new file mode 100644
index 0000000..e83334f
--- /dev/null
+++ b/man/getprogname.3
@@ -0,0 +1,95 @@
+.\"
+.\" Copyright (c) 2001 Christopher G. Demetriou
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"          This product includes software developed for the
+.\"          NetBSD Project.  See http://www.netbsd.org/ for
+.\"          information about NetBSD.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd May 1, 2001
+.Dt GETPROGNAME 3
+.Os
+.Sh NAME
+.Nm getprogname ,
+.Nm setprogname
+.Nd get or set the program name
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdlib.h
+.Ft const char *
+.Fn getprogname "void"
+.Ft void
+.Fn setprogname "const char *progname"
+.Sh DESCRIPTION
+The
+.Fn getprogname
+and
+.Fn setprogname
+functions manipulate the name of the current program.
+They are used by error-reporting routines to produce
+consistent output.
+.Pp
+The
+.Fn getprogname
+function returns the name of the program.
+If the name has not been set yet, it will return
+.Dv NULL .
+.Pp
+The
+.Fn setprogname
+function sets the name of the program to be the last component of the
+.Fa progname
+argument.
+Since a pointer to the given string is kept as the program name,
+it should not be modified for the rest of the program's lifetime.
+.Pp
+In
+.Fx ,
+the name of the program is set by the start-up code that is run before
+.Fn main ;
+thus,
+running
+.Fn setprogname
+is not necessary.
+Programs that desire maximum portability should still call it;
+on another operating system,
+these functions may be implemented in a portability library.
+Calling
+.Fn setprogname
+allows the aforementioned library to learn the program name without
+modifications to the start-up code.
+.Sh SEE ALSO
+.Xr err 3 ,
+.Xr setproctitle 3
+.Sh HISTORY
+These functions first appeared in
+.Nx 1.6 ,
+and made their way into
+.Fx 4.4 .
diff --git a/man/setprogname.3 b/man/setprogname.3
new file mode 100644
index 0000000..66c00cf
--- /dev/null
+++ b/man/setprogname.3
@@ -0,0 +1 @@
+.so man3/getprogname.3
commit c1d086c224c1c98832d448a3e817767530d22e71
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat May 14 14:18:57 2011 +0200

    Add new man page for setproctitle(3)
    
    Taken from FreeBSD.

diff --git a/COPYING b/COPYING
index a3000de..57ba600 100644
--- a/COPYING
+++ b/COPYING
@@ -138,6 +138,27 @@
 
     --
 
+    Copyright © 1995 Peter Wemm <peter at FreeBSD.org>
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, is permitted provided that the following conditions
+    are met:
+    1. Redistributions of source code must retain the above copyright
+       notice immediately at the beginning of the file, without modification,
+       this list of conditions, and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the distribution.
+    3. This work was done expressly for inclusion into FreeBSD.  Other use
+       is permitted provided this notation is included.
+    4. Absolutely no warranty of function or purpose is made by the author
+       Peter Wemm.
+    5. Modifications may be freely made to this file providing the above
+       conditions are met.
+
+    --
+
     Copyright © 1997-2000, 2002, 2005, 2006, 2008 The NetBSD Foundation, Inc.
     All rights reserved.
 
diff --git a/man/Makefile.am b/man/Makefile.am
index 01415ba..d0f2271 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -37,6 +37,7 @@ dist_man_MANS = \
 	readpassphrase.3 \
 	reallocf.3 \
 	setmode.3 \
+	setproctitle.3 \
 	sradixsort.3 \
 	strlcat.3 \
 	strlcpy.3 \
diff --git a/man/setproctitle.3 b/man/setproctitle.3
new file mode 100644
index 0000000..d42498e
--- /dev/null
+++ b/man/setproctitle.3
@@ -0,0 +1,124 @@
+.\" Copyright (c) 1995 Peter Wemm <peter at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, is permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice immediately at the beginning of the file, without modification,
+.\"    this list of conditions, and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. This work was done expressly for inclusion into FreeBSD.  Other use
+.\"    is permitted provided this notation is included.
+.\" 4. Absolutely no warranty of function or purpose is made by the author
+.\"    Peter Wemm.
+.\" 5. Modifications may be freely made to this file providing the above
+.\"    conditions are met.
+.\"
+.\" $FreeBSD$
+.\"
+.\" The following requests are required for all man pages.
+.Dd December 16, 1995
+.Dt SETPROCTITLE 3
+.Os
+.Sh NAME
+.Nm setproctitle
+.Nd set process title
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/types.h
+.In bsd/unistd.h
+.Ft void
+.Fn setproctitle "const char *fmt" "..."
+.Sh DESCRIPTION
+The
+.Fn setproctitle
+library routine sets the process title that appears on the
+.Xr ps 1
+command.
+.Pp
+The title is set from the executable's name, followed by the
+result of a
+.Xr printf 3
+style expansion of the arguments as specified by the
+.Va fmt
+argument.
+If the
+.Va fmt
+argument begins with a
+.Dq -
+character, the executable's name is skipped.
+.Pp
+If
+.Va fmt
+is NULL, the process title is restored.
+.Sh EXAMPLES
+To set the title on a daemon to indicate its activity:
+.Bd -literal -offset indent
+setproctitle("talking to %s", inet_ntoa(addr));
+.Ed
+.Sh SEE ALSO
+.Xr ps 1 ,
+.Xr w 1 ,
+.Xr kvm 3 ,
+.Xr kvm_getargv 3 ,
+.Xr printf 3
+.Sh STANDARDS
+The
+.Fn setproctitle
+function
+is implicitly non-standard.
+Other methods of causing the
+.Xr ps 1
+command line to change, including copying over the argv[0] string are
+also implicitly non-portable.
+It is preferable to use an operating system
+supplied
+.Fn setproctitle
+if present.
+.Pp
+Unfortunately, it is possible that there are other calling conventions
+to other versions of
+.Fn setproctitle ,
+although none have been found by the author as yet.
+This is believed to be
+the predominant convention.
+.Pp
+It is thought that the implementation is compatible with other systems,
+including
+.Nx
+and
+.Bsx .
+.Sh HISTORY
+The
+.Fn setproctitle
+function
+first appeared in
+.Fx 2.2 .
+Other operating systems have
+similar functions.
+.Sh AUTHORS
+.An -nosplit
+.An Peter Wemm Aq peter at FreeBSD.org
+stole the idea from the
+.Sy "Sendmail 8.7.3"
+source code by
+.An Eric Allman Aq eric at sendmail.org .
+.Sh BUGS
+Never pass a string with user-supplied data as a format without using
+.Ql %s .
+An attacker can put format specifiers in the string to mangle your stack,
+leading to a possible security hole.
+This holds true even if the string was built using a function like
+.Fn snprintf ,
+as the resulting string may still contain user-supplied conversion specifiers
+for later interpolation by
+.Fn setproctitle .
+.Pp
+Always use the proper secure idiom:
+.Pp
+.Dl setproctitle("%s", string);
commit e37293a18a55e5c3be33725527f65ccb4025ca6c
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jan 12 18:16:55 2012 +0100

    Add <bitstring.h> for compatibility with NetBSD and OpenBSD

diff --git a/include/Makefile.am b/include/Makefile.am
index 2e3f3ec..2141570 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -8,6 +8,7 @@ nobase_include_HEADERS = \
 	bsd/sys/queue.h \
 	bsd/sys/tree.h \
 	bsd/netinet/ip_icmp.h \
+	bsd/bitstring.h \
 	bsd/bsd.h \
 	bsd/err.h \
 	bsd/getopt.h \
diff --git a/include/bsd/bitstring.h b/include/bsd/bitstring.h
new file mode 100644
index 0000000..12cbaf9
--- /dev/null
+++ b/include/bsd/bitstring.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright © 2012 Guillem Jover <guillem at hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* For compatibility with NetBSD and OpenBSD. */
+#ifdef LIBBSD_OVERLAY
+#include <sys/bitstring.h>
+#else
+#include <bsd/sys/bitstring.h>
+#endif
commit 34bf1068a27add441a0d6ef90ead4ed644c71c80
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Mar 23 10:43:33 2012 +0100

    test: Add a unit test for endian encoder/decoder

diff --git a/test/.gitignore b/test/.gitignore
index ecfa218..1c5d1f8 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,2 +1,3 @@
+endian
 headers
 overlay
diff --git a/test/Makefile.am b/test/Makefile.am
index 03ecb58..f280136 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,6 +13,7 @@ AM_CPPFLAGS = \
 check_PROGRAMS = \
 	headers \
 	overlay \
+	endian \
 	$(nil)
 
 TESTS = $(check_PROGRAMS)
diff --git a/test/endian.c b/test/endian.c
new file mode 100644
index 0000000..349675f
--- /dev/null
+++ b/test/endian.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2012 Guillem Jover <guillem at hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/endian.h>
+
+#include <assert.h>
+#include <string.h>
+
+int
+main()
+{
+	unsigned char decstream[] = {
+		0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+	};
+	unsigned char encstream[sizeof(decstream)];
+
+	assert(be16dec(decstream) == 0x0011);
+	assert(le16dec(decstream) == 0x1100);
+
+	assert(be32dec(decstream) == 0x00112233);
+	assert(le32dec(decstream) == 0x33221100);
+
+	assert(be64dec(decstream) == 0x0011223344556677);
+	assert(le64dec(decstream) == 0x7766554433221100);
+
+	memset(encstream, 0, sizeof(encstream));
+	be16enc(encstream, 0x1100);
+	assert(memcmp(encstream, decstream, sizeof(uint16_t)));
+	le16enc(encstream, 0x0011);
+	assert(memcmp(encstream, decstream, sizeof(uint16_t)));
+
+	memset(encstream, 0, sizeof(encstream));
+	be32enc(encstream, 0x33221100);
+	assert(memcmp(encstream, decstream, sizeof(uint32_t)));
+	le32enc(encstream, 0x00112233);
+	assert(memcmp(encstream, decstream, sizeof(uint32_t)));
+
+	memset(encstream, 0, sizeof(encstream));
+	be64enc(encstream, 0x7766554433221100);
+	assert(memcmp(encstream, decstream, sizeof(uint64_t)));
+	le64enc(encstream, 0x0011223344556677);
+	assert(memcmp(encstream, decstream, sizeof(uint64_t)));
+
+	return 0;
+}
commit 4eab0cc35130d182e5ab54ab13a0c9a0a8405886
Author: Robert Millan <rmh at debian.org>
Date:   Tue Jan 3 05:29:36 2012 +0100

    Add inline endian encoding/decoding functions
    
    Taken from FreeBSD.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/COPYING b/COPYING
index ba85b35..a3000de 100644
--- a/COPYING
+++ b/COPYING
@@ -278,6 +278,32 @@
 
     --
 
+    Copyright © 2002 Thomas Moestl <tmm at FreeBSD.org>
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions
+    are met:
+    1. Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+    SUCH DAMAGE.
+
+    --
+
     Copyright © 2005 Pawel Jakub Dawidek <pjd at FreeBSD.org>
     All rights reserved.
 
diff --git a/include/bsd/sys/endian.h b/include/bsd/sys/endian.h
index 3506cee..58fca50 100644
--- a/include/bsd/sys/endian.h
+++ b/include/bsd/sys/endian.h
@@ -49,4 +49,140 @@
 #define _PDP_ENDIAN __PDP_ENDIAN
 #endif
 
+/*
+ * Copyright © 2002 Thomas Moestl <tmm at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+
+/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
+
+static __inline uint16_t
+be16dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return ((p[0] << 8) | p[1]);
+}
+
+static __inline uint32_t
+be32dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+static __inline uint64_t
+be64dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
+}
+
+static __inline uint16_t
+le16dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return ((p[1] << 8) | p[0]);
+}
+
+static __inline uint32_t
+le32dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+}
+
+static __inline uint64_t
+le64dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
+}
+
+static __inline void
+be16enc(void *pp, uint16_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = (u >> 8) & 0xff;
+	p[1] = u & 0xff;
+}
+
+static __inline void
+be32enc(void *pp, uint32_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = (u >> 24) & 0xff;
+	p[1] = (u >> 16) & 0xff;
+	p[2] = (u >> 8) & 0xff;
+	p[3] = u & 0xff;
+}
+
+static __inline void
+be64enc(void *pp, uint64_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	be32enc(p, (uint32_t)(u >> 32));
+	be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
+}
+
+static __inline void
+le16enc(void *pp, uint16_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = u & 0xff;
+	p[1] = (u >> 8) & 0xff;
+}
+
+static __inline void
+le32enc(void *pp, uint32_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = u & 0xff;
+	p[1] = (u >> 8) & 0xff;
+	p[2] = (u >> 16) & 0xff;
+	p[3] = (u >> 24) & 0xff;
+}
+
+static __inline void
+le64enc(void *pp, uint64_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	le32enc(p, (uint32_t)(u & 0xffffffffU));
+	le32enc(p + 4, (uint32_t)(u >> 32));
+}
+
 #endif
commit 752997462a922402531c92b22dd7ab5af352f408
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 08:58:01 2012 +0100

    Base getprogname() on program_invocation_short_name presence instead of glibc

diff --git a/configure.ac b/configure.ac
index 0304f57..54da101 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,15 @@ AC_CHECK_DECL([F_CLOSEM],
                #include <fcntl.h>])
 
 # Checks for library functions.
+AC_MSG_CHECKING([for program_invocation_short_name])
+AC_LINK_IFELSE(
+	[AC_LANG_PROGRAM([[#include <errno.h>]],
+	                 [[const char *p = program_invocation_short_name;]])],
+	[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
+	           [Define to 1 if you have program_invocation_short_name])
+	 AC_MSG_RESULT([yes])],
+	[AC_MSG_RESULT([no])])
+
 AC_MSG_CHECKING([for __progname])
 AC_LINK_IFELSE(
 	[AC_LANG_PROGRAM([[]],
diff --git a/src/progname.c b/src/progname.c
index 4d0fee7..9bc5e4b 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -42,7 +42,7 @@ static const char *__progname = NULL;
 const char *
 getprogname(void)
 {
-#ifdef __GLIBC__
+#if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME)
 	if (__progname == NULL)
 		__progname = program_invocation_short_name;
 #elif defined(HAVE_GETEXECNAME)
commit d5d91869372f50d755cfa66803a52eece02dee43
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 09:08:35 2012 +0100

    Base fpurge() implementation on __fpurge presence instead of glibc

diff --git a/configure.ac b/configure.ac
index fd8b5d7..0304f57 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ AC_LINK_IFELSE(
 	 AC_MSG_RESULT([yes])],
 	[AC_MSG_RESULT([no])])
 
-AC_CHECK_FUNCS([dirfd getexecname getline sysconf])
+AC_CHECK_FUNCS([dirfd __fpurge getexecname getline sysconf])
 
 AC_CONFIG_FILES([
 	Makefile
diff --git a/src/fpurge.c b/src/fpurge.c
index 051b625..e2483f2 100644
--- a/src/fpurge.c
+++ b/src/fpurge.c
@@ -28,7 +28,7 @@
 #include <stdio.h>
 #include <stdio_ext.h>
 
-#ifdef __GLIBC__
+#ifdef HAVE___FPURGE
 int
 fpurge(FILE *fp)
 {
commit f8e80630796cd65ada70f9bf49a8737cfcd444ca
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 08:40:18 2012 +0100

    Base fgetln() implementation on getline presence instead of glibc

diff --git a/configure.ac b/configure.ac
index ce697a3..fd8b5d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ AC_LINK_IFELSE(
 	 AC_MSG_RESULT([yes])],
 	[AC_MSG_RESULT([no])])
 
-AC_CHECK_FUNCS([dirfd getexecname sysconf])
+AC_CHECK_FUNCS([dirfd getexecname getline sysconf])
 
 AC_CONFIG_FILES([
 	Makefile
diff --git a/src/fgetln.c b/src/fgetln.c
index b79584c..87bd2e9 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -30,7 +30,7 @@
 #include <sys/types.h>
 #include <string.h>
 
-#ifdef __GLIBC__
+#ifdef HAVE_GETLINE
 char *
 fgetln(FILE *stream, size_t *len)
 {
commit 786d1439207b689fb0219ab38f535891ec90dbf1
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Mar 24 20:37:55 2012 +0100

    test: Add new overlay unit test

diff --git a/test/.gitignore b/test/.gitignore
index 4237ec7..ecfa218 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1 +1,2 @@
 headers
+overlay
diff --git a/test/Makefile.am b/test/Makefile.am
index 30749c2..03ecb58 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -12,6 +12,7 @@ AM_CPPFLAGS = \
 
 check_PROGRAMS = \
 	headers \
+	overlay \
 	$(nil)
 
 TESTS = $(check_PROGRAMS)
diff --git a/test/overlay.c b/test/overlay.c
new file mode 100644
index 0000000..f748f1b
--- /dev/null
+++ b/test/overlay.c
@@ -0,0 +1,23 @@
+/* Include system headers that are “known” to pull bits selectively from
+ * other headers through magic macros, to check that the overlay is working
+ * properly. */
+#include <errno.h>
+#include <grp.h>
+#include <stdint.h>
+
+/* Include libbsd overlayed headers that might get partially included. */
+#include <sys/cdefs.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main()
+{
+	/* Test that we do not get partial definitions. */
+	fflush(stdout);
+
+	return 0;
+}
commit 866f73af914ba72815cb94d6c42ba4620fb22350
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 05:39:22 2012 +0100

    Move overlay inclusions outside of header protection
    
    Glibc tends to include standard headers with special definitions
    that make few declarations or macros visible, this stomps over the
    overlay #include_next <> logic.
    
    Based-on-patch-by: Robert Millan <rmh at debian.org>

diff --git a/include/bsd/err.h b/include/bsd/err.h
index def4ac3..11d1250 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -25,6 +25,12 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef LIBBSD_OVERLAY
+#include_next <err.h>
+#else
+#include <err.h>
+#endif
+
 #ifndef LIBBSD_ERR_H
 #define LIBBSD_ERR_H
 
@@ -32,12 +38,6 @@
 
 #include <stdarg.h>
 
-#ifdef LIBBSD_OVERLAY
-#include_next <err.h>
-#else
-#include <err.h>
-#endif
-
 __BEGIN_DECLS
 extern void warnc (int code, const char *format, ...);
 extern void vwarnc (int code, const char *format, va_list ap);
diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index 52a8f9c..9fb2e7e 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -24,9 +24,6 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_GETOPT_H
-#define LIBBSD_GETOPT_H
-
 #ifdef LIBBSD_OVERLAY
 #include_next <getopt.h>
 #include <unistd.h>
@@ -34,5 +31,3 @@
 #include <getopt.h>
 #include <bsd/unistd.h>
 #endif
-
-#endif
diff --git a/include/bsd/stdio.h b/include/bsd/stdio.h
index db2823e..22e9d2c 100644
--- a/include/bsd/stdio.h
+++ b/include/bsd/stdio.h
@@ -24,18 +24,18 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_STDIO_H
-#define LIBBSD_STDIO_H
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
 #ifdef LIBBSD_OVERLAY
 #include_next <stdio.h>
 #else
 #include <stdio.h>
 #endif
 
+#ifndef LIBBSD_STDIO_H
+#define LIBBSD_STDIO_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
 __BEGIN_DECLS
 const char *fmtcheck(const char *, const char *);
 
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 5253183..5448011 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -26,13 +26,6 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_STDLIB_H
-#define LIBBSD_STDLIB_H
-
-#include <sys/cdefs.h>
-#include <sys/stat.h>
-#include <stdint.h>
-
 #ifdef LIBBSD_OVERLAY
 #include_next <stdlib.h>
 #else
@@ -46,6 +39,13 @@
 #include <bsd/libutil.h>
 #endif
 
+#ifndef LIBBSD_STDLIB_H
+#define LIBBSD_STDLIB_H
+
+#include <sys/cdefs.h>
+#include <sys/stat.h>
+#include <stdint.h>
+
 __BEGIN_DECLS
 u_int32_t arc4random();
 void arc4random_stir();
diff --git a/include/bsd/string.h b/include/bsd/string.h
index be811f3..ac2a5a5 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -24,18 +24,18 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_STRING_H
-#define LIBBSD_STRING_H
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
 #ifdef LIBBSD_OVERLAY
 #include_next <string.h>
 #else
 #include <string.h>
 #endif
 
+#ifndef LIBBSD_STRING_H
+#define LIBBSD_STRING_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
 __BEGIN_DECLS
 size_t strlcpy(char *dst, const char *src, size_t siz);
 size_t strlcat(char *dst, const char *src, size_t siz);
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index 90b34c1..49bbeb5 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -24,15 +24,15 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_SYS_CDEFS_H
-#define LIBBSD_SYS_CDEFS_H
-
 #ifdef LIBBSD_OVERLAY
 #include_next <sys/cdefs.h>
 #else
 #include <sys/cdefs.h>
 #endif
 
+#ifndef LIBBSD_SYS_CDEFS_H
+#define LIBBSD_SYS_CDEFS_H
+
 /*
  * Some kFreeBSD headers expect those macros to be set for sanity checks.
  */
diff --git a/include/bsd/sys/endian.h b/include/bsd/sys/endian.h
index cf8c884..3506cee 100644
--- a/include/bsd/sys/endian.h
+++ b/include/bsd/sys/endian.h
@@ -24,15 +24,15 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_SYS_ENDIAN_H
-#define LIBBSD_SYS_ENDIAN_H
-
 #ifdef LIBBSD_OVERLAY
 #include_next <endian.h>
 #else
 #include <endian.h>
 #endif
 
+#ifndef LIBBSD_SYS_ENDIAN_H
+#define LIBBSD_SYS_ENDIAN_H
+
 #ifndef _BYTE_ORDER
 #define _BYTE_ORDER __BYTE_ORDER
 #endif
diff --git a/include/bsd/sys/poll.h b/include/bsd/sys/poll.h
index 227effa..0e34103 100644
--- a/include/bsd/sys/poll.h
+++ b/include/bsd/sys/poll.h
@@ -24,15 +24,15 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_SYS_POLL_H
-#define LIBBSD_SYS_POLL_H
-
 #ifdef LIBBSD_OVERLAY
 #include_next <sys/poll.h>
 #else
 #include <sys/poll.h>
 #endif
 
+#ifndef LIBBSD_SYS_POLL_H
+#define LIBBSD_SYS_POLL_H
+
 #ifndef INFTIM
 #define INFTIM (-1)
 #endif
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index 713a8d7..e576b89 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -25,18 +25,18 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LIBBSD_UNISTD_H
-#define LIBBSD_UNISTD_H
-
-#include <sys/cdefs.h>
-#include <sys/stat.h>
-
 #ifdef LIBBSD_OVERLAY
 #include_next <unistd.h>
 #else
 #include <unistd.h>
 #endif
 
+#ifndef LIBBSD_UNISTD_H
+#define LIBBSD_UNISTD_H
+
+#include <sys/cdefs.h>
+#include <sys/stat.h>
+
 #ifndef S_ISTXT
 #define S_ISTXT S_ISVTX
 #endif
commit f71d8e050178ab23ab9b06ee4ccab901ce4284bf
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Mar 21 04:10:37 2012 +0100

    Remove bogus deprecation warning from <getopt.h>

diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index 697f940..52a8f9c 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -31,7 +31,6 @@
 #include_next <getopt.h>
 #include <unistd.h>
 #else
-#warning "Deprecated header, use <bsd/unistd.h> or <unistd.h> with libbsd-overlay.pc instead."
 #include <getopt.h>
 #include <bsd/unistd.h>
 #endif
commit 0b96e1a218b700448adf3c016ab25c11f207f6f6
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 07:32:53 2012 +0100

    Remove deprecated compatibility includes in headers

diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h
index c083805..b46056a 100644
--- a/include/bsd/bsd.h
+++ b/include/bsd/bsd.h
@@ -41,9 +41,4 @@
 #include <bsd/getopt.h>
 #include <bsd/md5.h>
 
-/* FIXME: Will be removed in the future. */
-#ifndef LIBBSD_DISABLE_DEPRECATED
-#include <time.h>
-#endif
-
 #endif
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 217a416..5253183 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -46,17 +46,6 @@
 #include <bsd/libutil.h>
 #endif
 
-/* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */
-#ifndef LIBBSD_DISABLE_DEPRECATED
-#ifdef LIBBSD_OVERLAY
-#include <stdio.h>
-#include <unistd.h>
-#else
-#include <bsd/stdio.h>
-#include <bsd/unistd.h>
-#endif
-#endif
-
 __BEGIN_DECLS
 u_int32_t arc4random();
 void arc4random_stir();
diff --git a/include/bsd/string.h b/include/bsd/string.h
index fb7d4a7..be811f3 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -36,15 +36,6 @@
 #include <string.h>
 #endif
 
-#ifndef LIBBSD_DISABLE_DEPRECATED
-/* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
-#ifdef LIBBSD_OVERLAY
-#include <stdio.h>
-#else
-#include <bsd/stdio.h>
-#endif
-#endif
-
 __BEGIN_DECLS
 size_t strlcpy(char *dst, const char *src, size_t siz);
 size_t strlcat(char *dst, const char *src, size_t siz);
commit 109cafb3932c5c74500e1f53e54059670a173cfb
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 07:32:37 2012 +0100

    Remove deprecated headers

diff --git a/include/Makefile.am b/include/Makefile.am
index 0201c28..2e3f3ec 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -9,23 +9,15 @@ nobase_include_HEADERS = \
 	bsd/sys/tree.h \
 	bsd/netinet/ip_icmp.h \
 	bsd/bsd.h \
-	bsd/cdefs.h \
 	bsd/err.h \
 	bsd/getopt.h \
-	bsd/inet.h \
-	bsd/ip_icmp.h \
 	bsd/libutil.h \
 	bsd/md5.h \
 	bsd/nlist.h \
-	bsd/queue.h \
-	bsd/random.h \
 	bsd/readpassphrase.h \
 	bsd/stdio.h \
 	bsd/stdlib.h \
 	bsd/string.h \
 	bsd/unistd.h \
 	bsd/vis.h \
-	libutil.h \
-	nlist.h \
-	vis.h \
 	$(nil)
diff --git a/include/bsd/cdefs.h b/include/bsd/cdefs.h
deleted file mode 100644
index 0f23e86..0000000
--- a/include/bsd/cdefs.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2009 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_BSD_CDEFS_H
-#define LIBBSD_BSD_CDEFS_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/sys/cdefs.h> or libbsd-overlay.pc instead."
-#else
-#warning "Deprecated header, use <bsd/sys/cdefs.h> or libbsd-overlay.pc instead."
-#endif
-
-#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
-#else
-#include <bsd/sys/cdefs.h>
-#endif
-
-#endif
diff --git a/include/bsd/inet.h b/include/bsd/inet.h
deleted file mode 100644
index ed4dd1b..0000000
--- a/include/bsd/inet.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2008, 2009 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_INET_H
-#define LIBBSD_INET_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <arpa/inet.h> instead."
-#else
-#warning "Deprecated header, use <arpa/inet.h> instead."
-#endif
-
-#include <arpa/inet.h>
-
-#endif
diff --git a/include/bsd/ip_icmp.h b/include/bsd/ip_icmp.h
deleted file mode 100644
index accd399..0000000
--- a/include/bsd/ip_icmp.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2009 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_BSD_IP_ICMP_H
-#define LIBBSD_BSD_IP_ICMP_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/netinet/ip_icmp.h> or libbsd-overlay.pc instead."
-#else
-#warning "Deprecated header, use <bsd/netinet/ip_icmp.h> or libbsd-overlay.pc instead."
-#endif
-
-#ifdef LIBBSD_OVERLAY
-#include <netinet/ip_icmp.h>
-#else
-#include <bsd/netinet/ip_icmp.h>
-#endif
-
-#endif
diff --git a/include/bsd/queue.h b/include/bsd/queue.h
deleted file mode 100644
index d8e0806..0000000
--- a/include/bsd/queue.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2009 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_BSD_QUEUE_H
-#define LIBBSD_BSD_QUEUE_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/sys/queue.h> or libbsd-overlay.pc instead."
-#else
-#warning "Deprecated header, use <bsd/sys/queue.h> or libbsd-overlay.pc instead."
-#endif
-
-#ifdef LIBBSD_OVERLAY
-#include <sys/queue.h>
-#else
-#include <bsd/sys/queue.h>
-#endif
-
-#endif
diff --git a/include/bsd/random.h b/include/bsd/random.h
deleted file mode 100644
index 80d0308..0000000
--- a/include/bsd/random.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2004, 2005, 2009 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_RANDOM_H
-#define LIBBSD_RANDOM_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/stdlib.h> instead."
-#else
-#warning "Deprecated header, use <bsd/stdlib.h> instead."
-#endif
-
-#ifdef LIBBSD_OVERLAY
-#include <stdlib.h>
-#else
-#include <bsd/stdlib.h>
-#endif
-
-#endif
diff --git a/include/libutil.h b/include/libutil.h
deleted file mode 100644
index a995c4a..0000000
--- a/include/libutil.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2011 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_LIBUTIL_H
-#define LIBBSD_LIBUTIL_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/libutil.h> or libbsd-overlay.pc instead."
-#else
-#warning "Deprecated header, use <bsd/libutil.h> or libbsd-overlay.pc instead."
-#endif
-
-#include <bsd/libutil.h>
-
-#endif
diff --git a/include/nlist.h b/include/nlist.h
deleted file mode 100644
index ac04b1d..0000000
--- a/include/nlist.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2011 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_DEPRECATED_NLIST_H
-#define LIBBSD_DEPRECATED_NLIST_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/nlist.h> or libbsd-overlay.pc instead."
-#else
-#warning "Deprecated header, use <bsd/nlist.h> or libbsd-overlay.pc instead."
-#endif
-
-#include <bsd/nlist.h>
-
-#endif
diff --git a/include/vis.h b/include/vis.h
deleted file mode 100644
index 16f7976..0000000
--- a/include/vis.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2011 Guillem Jover
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LIBBSD_VIS_H
-#define LIBBSD_VIS_H
-
-#ifdef LIBBSD_DISABLE_DEPRECATED
-#error "Deprecated header, use <bsd/vis.h> or libbsd-overlay.pc instead."
-#else
-#warning "Deprecated header, use <bsd/vis.h> or libbsd-overlay.pc instead."
-#endif
-
-#include <bsd/vis.h>
-
-#endif
commit 64348583148e2ae3b97e27916b90bbbe0b74461e
Author: Robert Millan <rmh at debian.org>
Date:   Sat Dec 31 04:30:48 2011 +0100

    Add new expand_number() function
    
    Taken from FreeBSD.
    
    [guillem at hadrons.org:
     - Include <stdint.h> in <bsd/libutil.h>. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/COPYING b/COPYING
index a69e7b6..ba85b35 100644
--- a/COPYING
+++ b/COPYING
@@ -304,6 +304,33 @@
 
     --
 
+    Copyright © 2007 Eric Anderson <anderson at FreeBSD.org>
+    Copyright © 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions
+    are met:
+    1. Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+    SUCH DAMAGE.
+
+    --
+
     Copyright © 2007 Dag-Erling Coïdan Smørgrav
     All rights reserved.
 
diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h
index 21a22cd..648473c 100644
--- a/include/bsd/libutil.h
+++ b/include/bsd/libutil.h
@@ -41,6 +41,7 @@
 
 #include <features.h>
 #include <sys/types.h>
+#include <stdint.h>
 
 /* for pidfile.c */
 struct pidfh {
@@ -53,6 +54,7 @@ struct pidfh {
 __BEGIN_DECLS
 int humanize_number(char *buf, size_t len, int64_t bytes,
     const char *suffix, int scale, int flags);
+int expand_number(const char *_buf, uint64_t *_num);
 
 int flopen(const char *_path, int _flags, ...);
 
diff --git a/man/Makefile.am b/man/Makefile.am
index 8188488..01415ba 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -21,6 +21,7 @@ dist_man_MANS = \
 	arc4random_uniform.3 \
 	closefrom.3 \
 	dehumanize_number.3 \
+	expand_number.3 \
 	fgetln.3 \
 	flopen.3 \
 	fmtcheck.3 \
diff --git a/man/expand_number.3 b/man/expand_number.3
new file mode 100644
index 0000000..482637d
--- /dev/null
+++ b/man/expand_number.3
@@ -0,0 +1,87 @@
+.\" Copyright (c) 2007 Eric Anderson <anderson at FreeBSD.org>
+.\" Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd August 15, 2010
+.Dt EXPAND_NUMBER 3
+.Os
+.Sh NAME
+.Nm expand_number
+.Nd format a number from human readable form
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/libutil.h
+.Ft int
+.Fo expand_number
+.Fa "const char *buf" "uint64_t *num"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn expand_number
+function unformats the
+.Fa buf
+string and stores a unsigned 64-bit quantity at address pointed out by the
+.Fa num
+argument.
+.Pp
+The
+.Fn expand_number
+function
+follows the SI power of two convention.
+.Pp
+The prefixes are:
+.Bl -column "Prefix" "Description" "1000000000000000000" -offset indent
+.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
+.It Li k Ta No kilo Ta 1024
+.It Li M Ta No mega Ta 1048576
+.It Li G Ta No giga Ta 1073741824
+.It Li T Ta No tera Ta 1099511627776
+.It Li P Ta No peta Ta 1125899906842624
+.It Li E Ta No exa  Ta 1152921504606846976
+.El
+.Sh RETURN VALUES
+.Rv -std
+.Sh ERRORS
+The
+.Fn expand_number
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The given string contains no digits.
+.It Bq Er EINVAL
+An unrecognized prefix was given.
+.It Bq Er ERANGE
+Result doesn't fit into 64 bits.
+.El
+.Sh SEE ALSO
+.Xr humanize_number 3
+.Sh HISTORY
+The
+.Fn expand_number
+function first appeared in
+.Fx 6.3 .
diff --git a/src/Makefile.am b/src/Makefile.am
index 98fae97..61d7119 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,6 +44,7 @@ libbsd_la_SOURCES = \
 	closefrom.c \
 	dehumanize_number.c \
 	err.c \
+	expand_number.c \
 	fgetln.c \
 	flopen.c \
 	fmtcheck.c \
diff --git a/src/expand_number.c b/src/expand_number.c
new file mode 100644
index 0000000..5d55884
--- /dev/null
+++ b/src/expand_number.c
@@ -0,0 +1,101 @@
+/*-
+ * Copyright (c) 2007 Eric Anderson <anderson at FreeBSD.org>
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <libutil.h>
+#include <stdint.h>
+
+/*
+ * Convert an expression of the following forms to a uint64_t.
+ *	1) A positive decimal number.
+ *	2) A positive decimal number followed by a 'b' or 'B' (mult by 1).
+ *	3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
+ *	4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
+ *	5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
+ *	6) A positive decimal number followed by a 't' or 'T' (mult by 1 << 40).
+ *	7) A positive decimal number followed by a 'p' or 'P' (mult by 1 << 50).
+ *	8) A positive decimal number followed by a 'e' or 'E' (mult by 1 << 60).
+ */
+int
+expand_number(const char *buf, uint64_t *num)
+{
+	uint64_t number;
+	unsigned shift;
+	char *endptr;
+
+	number = strtoumax(buf, &endptr, 0);
+
+	if (endptr == buf) {
+		/* No valid digits. */
+		errno = EINVAL;
+		return (-1);
+	}
+
+	switch (tolower((unsigned char)*endptr)) {
+	case 'e':
+		shift = 60;
+		break;
+	case 'p':
+		shift = 50;
+		break;
+	case 't':
+		shift = 40;
+		break;
+	case 'g':
+		shift = 30;
+		break;
+	case 'm':
+		shift = 20;
+		break;
+	case 'k':
+		shift = 10;
+		break;
+	case 'b':
+	case '\0': /* No unit. */
+		*num = number;
+		return (0);
+	default:
+		/* Unrecognized unit. */
+		errno = EINVAL;
+		return (-1);
+	}
+
+	if ((number << shift) >> shift != number) {
+		/* Overflow */
+		errno = ERANGE;
+		return (-1);
+	}
+
+	*num = number << shift;
+	return (0);
+}
diff --git a/src/libbsd.map b/src/libbsd.map
index 1fa4619..5c4b174 100644
--- a/src/libbsd.map
+++ b/src/libbsd.map
@@ -92,4 +92,5 @@ LIBBSD_0.3 {
 
 LIBBSD_0.4 {
     closefrom;
+    expand_number;
 } LIBBSD_0.3;
commit 943939d0e57257c83a8113102eb9e9703963cc5c
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Dec 31 08:39:44 2011 +0100

    Add new closefrom() function
    
    Code taken from sudo, man page from FreeBSD.

diff --git a/COPYING b/COPYING
index e275e4b..a69e7b6 100644
--- a/COPYING
+++ b/COPYING
@@ -174,6 +174,33 @@
 
     --
 
+    Copyright (c) 2009 Advanced Computing Technologies LLC
+    Written by: John H. Baldwin <jhb at FreeBSD.org>
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions
+    are met:
+    1. Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+    ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+    SUCH DAMAGE.
+
+    --
+
     Copyright © 1998, M. Warner Losh <imp at freebsd.org>
     All rights reserved.
 
@@ -349,7 +376,8 @@
 
     --
 
-    Copyright © 2000-2002, 2007 Todd C. Miller <Todd.Miller at courtesan.com>
+    Copyright © 2000-2002, 2004-2005, 2007, 2010
+        Todd C. Miller <Todd.Miller at courtesan.com>
 
     Permission to use, copy, modify, and distribute this software for any
     purpose with or without fee is hereby granted, provided that the above
diff --git a/configure.ac b/configure.ac
index ab7f96a..ce697a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,7 @@ AC_PROG_LN_S
 # Checks for libraries.
 
 # Checks for header files.
+AC_CHECK_HEADERS([sys/ndir.h sys/dir.h dir.h dirent.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_UID_T
@@ -36,6 +37,13 @@ AC_TYPE_PID_T
 AC_TYPE_SIZE_T
 AC_TYPE_SSIZE_T
 
+AC_CHECK_DECL([F_CLOSEM],
+              [AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
+                         [Define to 1 if you have fcntl(F_CLOSEM)])],
+              [],
+              [#include <limits.h>
+               #include <fcntl.h>])
+
 # Checks for library functions.
 AC_MSG_CHECKING([for __progname])
 AC_LINK_IFELSE(
@@ -46,7 +54,7 @@ AC_LINK_IFELSE(
 	 AC_MSG_RESULT([yes])],
 	[AC_MSG_RESULT([no])])
 
-AC_CHECK_FUNCS([getexecname])
+AC_CHECK_FUNCS([dirfd getexecname sysconf])
 
 AC_CONFIG_FILES([
 	Makefile
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index b6f070a..713a8d7 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -54,6 +54,8 @@ int bsd_getopt(int argc, char * const argv[], const char *shortopts);
 mode_t getmode(const void *set, mode_t mode);
 void *setmode(const char *mode_str);
 
+void closefrom(int lowfd);
+
 void setproctitle(const char *fmt, ...);
 
 int getpeereid(int s, uid_t *euid, gid_t *egid);
diff --git a/man/Makefile.am b/man/Makefile.am
index 129949a..8188488 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -19,6 +19,7 @@ dist_man_MANS = \
 	arc4random_buf.3 \
 	arc4random_stir.3 \
 	arc4random_uniform.3 \
+	closefrom.3 \
 	dehumanize_number.3 \
 	fgetln.3 \
 	flopen.3 \
diff --git a/man/closefrom.3 b/man/closefrom.3
new file mode 100644
index 0000000..472c985
--- /dev/null
+++ b/man/closefrom.3
@@ -0,0 +1,54 @@
+.\" Copyright (c) 2009 Advanced Computing Technologies LLC
+.\" Written by: John H. Baldwin <jhb at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd June 12, 2009
+.Dt CLOSEFROM 3
+.Os
+.Sh NAME
+.Nm closefrom
+.Nd delete open file descriptors
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/unistd.h
+.Ft void
+.Fn closefrom "int lowfd"
+.Sh DESCRIPTION
+The
+.Fn closefrom
+system call deletes all open file descriptors greater than or equal to
+.Fa lowfd
+from the per-process object reference table.
+Any errors encountered while closing file descriptors are ignored.
+.Sh SEE ALSO
+.Xr close 2
+.Sh HISTORY
+The
+.Fn closefrom
+function first appeared in
+.Fx 8.0 .
diff --git a/src/Makefile.am b/src/Makefile.am
index 2713e8b..98fae97 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,7 @@ libbsd_la_LDFLAGS = \
 libbsd_la_SOURCES = \
 	arc4random.c \
 	bsd_getopt.c \
+	closefrom.c \
 	dehumanize_number.c \
 	err.c \
 	fgetln.c \
diff --git a/src/closefrom.c b/src/closefrom.c
new file mode 100644
index 0000000..b7e2ad5
--- /dev/null
+++ b/src/closefrom.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2004-2005, 2007, 2010
+ *	Todd C. Miller <Todd.Miller at courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <unistd.h>
+#include <stdio.h>
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif /* STDC_HEADERS */
+#include <fcntl.h>
+#ifdef HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# ifdef HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# ifdef HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# ifdef HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
+
+#ifndef OPEN_MAX
+# define OPEN_MAX 256
+#endif
+
+#ifndef HAVE_FCNTL_CLOSEM
+# ifndef HAVE_DIRFD
+#   define closefrom_fallback	closefrom
+# endif
+#endif
+
+/*
+ * Close all file descriptors greater than or equal to lowfd.
+ * This is the expensive (ballback) method.
+ */
+void
+closefrom_fallback(int lowfd)
+{
+	long fd, maxfd;
+
+	/*
+	 * Fall back on sysconf() or getdtablesize().  We avoid checking
+	 * resource limits since it is possible to open a file descriptor
+	 * and then drop the rlimit such that it is below the open fd.
+	 */
+#ifdef HAVE_SYSCONF
+	maxfd = sysconf(_SC_OPEN_MAX);
+#else
+	maxfd = getdtablesize();
+#endif /* HAVE_SYSCONF */
+	if (maxfd < 0)
+		maxfd = OPEN_MAX;
+
+	for (fd = lowfd; fd < maxfd; fd++)
+		(void)close((int)fd);
+}
+
+/*
+ * Close all file descriptors greater than or equal to lowfd.
+ * We try the fast way first, falling back on the slow method.
+ */
+#ifdef HAVE_FCNTL_CLOSEM
+void
+closefrom(int lowfd)
+{
+	if (fcntl(lowfd, F_CLOSEM, 0) == -1)
+		closefrom_fallback(lowfd);
+}
+#else
+# ifdef HAVE_DIRFD
+void
+closefrom(int lowfd)
+{
+	struct dirent *dent;
+	DIR *dirp;
+	char *endp;
+	long fd;
+
+	/* Use /proc/self/fd directory if it exists. */
+	dirp = opendir("/proc/self/fd");
+	if (dirp != NULL) {
+		while ((dent = readdir(dirp)) != NULL) {
+			fd = strtol(dent->d_name, &endp, 10);
+			if (dent->d_name != endp && *endp == '\0' &&
+			    fd >= 0 && fd < INT_MAX && fd >= lowfd &&
+			    fd != dirfd(dirp))
+				(void)close((int)fd);
+		}
+		(void)closedir(dirp);
+	} else
+		closefrom_fallback(lowfd);
+}
+#endif /* HAVE_DIRFD */
+#endif /* HAVE_FCNTL_CLOSEM */
diff --git a/src/libbsd.map b/src/libbsd.map
index 39e6ea9..1fa4619 100644
--- a/src/libbsd.map
+++ b/src/libbsd.map
@@ -89,3 +89,7 @@ LIBBSD_0.3 {
 
     fpurge;
 } LIBBSD_0.2;
+
+LIBBSD_0.4 {
+    closefrom;
+} LIBBSD_0.3;
commit 3d614131b598e52b34c487866dae4853df5ec86a
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Dec 31 06:01:27 2011 +0100

    Base errc() and warnc() on vwarnc() and verrc() respectively

diff --git a/src/err.c b/src/err.c
index e5c604d..4e50510 100644
--- a/src/err.c
+++ b/src/err.c
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2006 Robert Millan
+ * Copyright © 2011 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,15 +32,10 @@
 void
 warnc(int code, const char *format, ...)
 {
-	int tmp = errno;
 	va_list ap;
 
 	va_start(ap, format);
-
-	errno = code;
-	warn(format, ap);
-	errno = tmp;
-
+	vwarnc(code, format, ap);
 	va_end(ap);
 }
 
@@ -59,10 +55,7 @@ errc(int status, int code, const char *format, ...)
 	va_list ap;
 
 	va_start(ap, format);
-
-	errno = code;
-	err(status, format, ap);
-
+	verrc(status, code, format, ap);
 	va_end(ap);
 }
 
commit 87232260404f10c6884756796306f270a527628e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 6 16:29:26 2011 +0200

    Use system __progname variable in progname module if available

diff --git a/configure.ac b/configure.ac
index c9cf0a4..ab7f96a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,15 @@ AC_TYPE_SIZE_T
 AC_TYPE_SSIZE_T
 
 # Checks for library functions.
+AC_MSG_CHECKING([for __progname])
+AC_LINK_IFELSE(
+	[AC_LANG_PROGRAM([[]],
+	                 [[extern char *__progname;
+	                   const char *p = __progname;]])],
+	[AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
+	 AC_MSG_RESULT([yes])],
+	[AC_MSG_RESULT([no])])
+
 AC_CHECK_FUNCS([getexecname])
 
 AC_CONFIG_FILES([
diff --git a/src/progname.c b/src/progname.c
index b5132d8..4d0fee7 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -33,7 +33,11 @@
 #include <string.h>
 #include <stdlib.h>
 
+#ifdef HAVE___PROGNAME
+extern const char *__progname;
+#else
 static const char *__progname = NULL;
+#endif
 
 const char *
 getprogname(void)
commit b5cc17d66498c3da0aa862a517f630b4aa5d5dc6
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jul 5 23:27:31 2011 +0200

    Use getexecname() if available for getprogname()
    
    This function is present on Solaris.

diff --git a/configure.ac b/configure.ac
index 06a02b7..c9cf0a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,7 @@ AC_TYPE_SIZE_T
 AC_TYPE_SSIZE_T
 
 # Checks for library functions.
+AC_CHECK_FUNCS([getexecname])
 
 AC_CONFIG_FILES([
 	Makefile
diff --git a/src/progname.c b/src/progname.c
index f24071a..b5132d8 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2006 Robert Millan
- * Copyright © 2010-2011 Guillem Jover
+ * Copyright © 2010-2012 Guillem Jover <guillem at hadrons.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -41,6 +41,10 @@ getprogname(void)
 #ifdef __GLIBC__
 	if (__progname == NULL)
 		__progname = program_invocation_short_name;
+#elif defined(HAVE_GETEXECNAME)
+	/* getexecname(3) returns an absolute pathname, normalize it. */
+	if (__progname == NULL)
+		setprogname(getexecname());
 #endif
 
 	return __progname;
commit abf14c3940a5ec08bb9fce9ddfb7375309a4d97f
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Mar 24 20:37:55 2012 +0100

    test: Add new headers unit test

diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..4237ec7
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+headers
diff --git a/test/Makefile.am b/test/Makefile.am
index 6977948..30749c2 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -11,6 +11,7 @@ AM_CPPFLAGS = \
 	-D__REENTRANT
 
 check_PROGRAMS = \
+	headers \
 	$(nil)
 
 TESTS = $(check_PROGRAMS)
diff --git a/test/headers.c b/test/headers.c
new file mode 100644
index 0000000..bc429fd
--- /dev/null
+++ b/test/headers.c
@@ -0,0 +1,25 @@
+/* Check that all libbsd overlayed headers preprocess. */
+#include <sys/cdefs.h>
+#include <sys/endian.h>
+#include <sys/bitstring.h>
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/poll.h>
+
+#include <err.h>
+#include <getopt.h>
+#include <libutil.h>
+#include <md5.h>
+#include <nlist.h>
+#include <readpassphrase.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <vis.h>
+
+int
+main()
+{
+	return 0;
+}
commit 23973e2221628ba038119957543a49d72c8376d7
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Mar 23 10:43:33 2012 +0100

    build: Add a test suite infrastructure

diff --git a/Makefile.am b/Makefile.am
index 4a6a326..ae7cd20 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = include man src
+SUBDIRS = include man src test
 
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/configure.ac b/configure.ac
index b34b416..06a02b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,7 @@ AC_CONFIG_FILES([
 	src/Makefile
 	src/libbsd.pc
 	src/libbsd-overlay.pc
+	test/Makefile
 ])
 AC_CONFIG_HEADERS([config.h])
 AC_OUTPUT
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..6977948
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,16 @@
+## Process this file with automake to produce Makefile.in
+
+# Set default values for user variables
+CFLAGS = -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
+
+AM_CPPFLAGS = \
+	-I$(top_builddir) \
+	-isystem $(top_srcdir)/include/bsd/ \
+	-include $(top_builddir)/config.h \
+	-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
+	-D__REENTRANT
+
+check_PROGRAMS = \
+	$(nil)
+
+TESTS = $(check_PROGRAMS)
commit 980f04f77b7ddfcd047ef77b30677b678bebf711
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 08:58:52 2012 +0100

    build: Do not define already defined _GNU_SOURCE
    
    The macro is defined by configure on config.h which is now implicitly
    included by all source files.

diff --git a/src/Makefile.am b/src/Makefile.am
index 0bfeb07..2713e8b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,7 @@ AM_CPPFLAGS = \
 	-isystem $(top_srcdir)/include/bsd/ \
 	-include $(top_builddir)/config.h \
 	-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
-	-D_GNU_SOURCE -D__REENTRANT
+	-D__REENTRANT
 
 EXTRA_DIST = \
 	libbsd.map \
diff --git a/src/fpurge.c b/src/fpurge.c
index 19d6537..051b625 100644
--- a/src/fpurge.c
+++ b/src/fpurge.c
@@ -24,8 +24,6 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define _GNU_SOURCE 1
-
 #include <errno.h>
 #include <stdio.h>
 #include <stdio_ext.h>
commit 8d2f12d7f032312dd509599a867296059d5bfef7
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Jan 3 08:45:05 2012 +0100

    build: Include <config.h> through -include for all source files

diff --git a/src/Makefile.am b/src/Makefile.am
index 153c7b8..0bfeb07 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,6 +6,7 @@ CFLAGS = -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
 AM_CPPFLAGS = \
 	-I$(top_builddir) \
 	-isystem $(top_srcdir)/include/bsd/ \
+	-include $(top_builddir)/config.h \
 	-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
 	-D_GNU_SOURCE -D__REENTRANT
 
commit 88004b30ff173caac5d76f6d65750bb4144f3cec
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Dec 31 07:31:47 2011 +0100

    build: Set -Wno-unused-parameter to default CFLAGS

diff --git a/src/Makefile.am b/src/Makefile.am
index 9bd9257..153c7b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in
 
 # Set default values for user variables
-CFLAGS = -Wall -Wextra -Wno-unused-variable
+CFLAGS = -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
 
 AM_CPPFLAGS = \
 	-I$(top_builddir) \
commit dcaa93d9843d6e0ac77c48541036a69bc4cadd21
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 17 11:13:04 2010 +0100

    build: Switch to autotools

diff --git a/.gitignore b/.gitignore
index 799fb3d..20f33d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,19 @@
 ChangeLog
 *.pc
+*.la
 *.lo
 *.o
 *.so*
 *.a
+.deps/
+.libs/
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache/
+build-aux/
+configure
+config.*
+libtool
+m4/
+stamp-h1
diff --git a/Makefile b/Makefile
deleted file mode 100644
index ca7cb0e..0000000
--- a/Makefile
+++ /dev/null
@@ -1,237 +0,0 @@
-VERSION := $(shell ./get-version)
-
-LIB_NAME := libbsd
-LIB_VERSION_MAJOR := 0
-LIB_VERSION_MINOR := 3
-LIB_VERSION_MICRO := 0
-LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
-
-LIB_PKGCONFIG := src/$(LIB_NAME).pc
-LIB_PKGCONFIG_OVERLAY := src/$(LIB_NAME)-overlay.pc
-LIB_STATIC := $(LIB_NAME).a
-LIB_SHARED_SO := $(LIB_NAME).so
-LIB_SONAME := $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR)
-LIB_SHARED := $(LIB_SONAME).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
-
-TAR_NAME := $(LIB_NAME)-$(VERSION)
-TAR_FILE := $(TAR_NAME).tar.gz
-
-LIB_DIST := \
-	ChangeLog
-
-LIB_SRCS_GEN := \
-	hash/md5hl.c
-LIB_SRCS := \
-	arc4random.c \
-	bsd_getopt.c \
-	err.c \
-	fgetln.c \
-	flopen.c \
-	fpurge.c \
-	getpeereid.c \
-	heapsort.c \
-	merge.c \
-	humanize_number.c \
-	dehumanize_number.c \
-	inet_net_pton.c \
-	hash/md5.c \
-	pidfile.c \
-	readpassphrase.c \
-	reallocf.c \
-	setmode.c \
-	setproctitle.c \
-	strmode.c \
-	strtonum.c \
-	strlcat.c strlcpy.c \
-	fmtcheck.c \
-	nlist.c \
-	progname.c \
-	radixsort.c \
-	vis.c unvis.c \
-	$(LIB_SRCS_GEN)
-LIB_SRCS_GEN := $(patsubst %,src/%,$(LIB_SRCS_GEN))
-LIB_SRCS := $(patsubst %,src/%,$(LIB_SRCS))
-
-LIB_INCLUDES := \
-	bsd/cdefs.h \
-	bsd/queue.h \
-	bsd/ip_icmp.h \
-	bsd/sys/cdefs.h \
-	bsd/sys/bitstring.h \
-	bsd/sys/endian.h \
-	bsd/sys/poll.h \
-	bsd/sys/queue.h \
-	bsd/sys/tree.h \
-	bsd/netinet/ip_icmp.h \
-	bsd/err.h \
-	bsd/getopt.h \
-	bsd/inet.h \
-	bsd/random.h \
-	bsd/md5.h \
-	bsd/string.h \
-	bsd/bsd.h \
-	bsd/stdio.h \
-	bsd/stdlib.h \
-	bsd/readpassphrase.h \
-	bsd/unistd.h \
-	bsd/nlist.h \
-	bsd/vis.h \
-	bsd/libutil.h \
-	nlist.h \
-	vis.h \
-	libutil.h
-
-LIB_MANS_GEN := \
-	md5.3bsd
-LIB_MANS := \
-	arc4random.3 \
-	arc4random_addrandom.3 \
-	arc4random_buf.3 \
-	arc4random_stir.3 \
-	arc4random_uniform.3 \
-	dehumanize_number.3 \
-	strtonum.3 \
-	strlcpy.3 \
-	strlcat.3 \
-	fgetln.3 \
-	flopen.3 \
-	getpeereid.3 \
-	readpassphrase.3 \
-	reallocf.3 \
-	heapsort.3 \
-	humanize_number.3 \
-	fmtcheck.3 \
-	mergesort.3 \
-	radixsort.3 \
-	sradixsort.3 \
-	nlist.3 \
-	pidfile.3 \
-	setmode.3 \
-	getmode.3 \
-	strmode.3 \
-	unvis.3 \
-	vis.3 \
-	$(LIB_MANS_GEN)
-LIB_MANS_GEN := $(patsubst %,man/%,$(LIB_MANS_GEN))
-LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
-
-LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o)
-LIB_SHARED_OBJS := $(LIB_SRCS:%.c=%.lo)
-
-AR = ar
-CC = gcc
-CCLD = $(CC)
-
-# Set default values for user variables
-CPPFLAGS ?=
-CFLAGS ?= -g -Wall -Wextra -Wno-unused-variable
-LDFLAGS ?=
-
-# Internal makefile variables
-MK_CPPFLAGS := -isystem include/bsd/ \
-	-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
-	-D_GNU_SOURCE -D__REENTRANT
-MK_CFLAGS :=
-MK_LDFLAGS :=
-
-COMPILE = $(CC) $(MK_CPPFLAGS) $(CPPFLAGS) $(MK_CFLAGS) $(CFLAGS)
-LINK = $(CCLD) $(MK_CFLAGS) $(CFLAGS) $(MK_LDFLAGS) $(LDFLAGS)
-
-prefix		= /usr
-exec_prefix	=
-libdir		= ${exec_prefix}/lib
-usrlibdir	= ${prefix}/lib
-includedir	= ${prefix}/include
-pkgconfigdir	= ${usrlibdir}/pkgconfig
-mandir		= ${prefix}/share/man
-
-.PHONY: libs
-libs: $(LIB_STATIC) $(LIB_SHARED_SO) $(LIB_PKGCONFIG) $(LIB_PKGCONFIG_OVERLAY)
-
-.PHONY: man
-man: $(LIB_MANS)
-
-%.lo: %.c
-	$(COMPILE) -o $@ -DPIC -fPIC -c $<
-
-%.o: %.c
-	$(COMPILE) -o $@ -c $<
-
-man/md5.3bsd: man/mdX.3
-	sed -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g' $< > $@
-
-src/hash/md5hl.c: src/hash/helper.c
-	sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
-
-%.pc: %.pc.in
-	sed -e 's:@VERSION@:$(VERSION):' \
-	    -e 's:@prefix@:$(value prefix):' \
-	    -e 's:@exec_prefix@:$(value exec_prefix):' \
-	    -e 's:@libdir@:$(value usrlibdir):' \
-	    -e 's:@includedir@:$(value includedir):' \
-	    $< > $@
-
-$(LIB_STATIC): $(LIB_STATIC_OBJS)
-	$(AR) rcs $@ $^
-
-$(LIB_SHARED_SO): $(LIB_SONAME)
-	ln -fs $^ $@
-
-$(LIB_SONAME): $(LIB_SHARED)
-	ln -fs $^ $@
-
-$(LIB_SHARED): $(LIB_SHARED_OBJS)
-	$(LINK) \
-	  -shared \
-	  -Wl,-soname -Wl,$(LIB_SONAME) \
-	  -Wl,--version-script=src/libbsd.map \
-	  -o $@ $^
-
-.PHONY: ChangeLog
-ChangeLog:
-	-git log --stat -C >$@
-
-.PHONY: dist
-dist: $(LIB_DIST)
-	mkdir $(TAR_NAME)
-	echo $(VERSION) >$(TAR_NAME)/.dist-version
-	cp -a --parents $(LIB_DIST) `git ls-files` $(TAR_NAME)
-	tar czf $(TAR_FILE) --exclude=.gitignore $(TAR_NAME)
-	rm -rf $(TAR_NAME)
-	gpg -a -b $(TAR_FILE)
-
-.PHONY: install
-install: libs man
-	mkdir -p $(DESTDIR)$(libdir)
-	mkdir -p $(DESTDIR)$(usrlibdir)
-	mkdir -p $(DESTDIR)$(includedir)/bsd/
-	mkdir -p $(DESTDIR)$(includedir)/bsd/sys/
-	mkdir -p $(DESTDIR)$(includedir)/bsd/netinet/
-	mkdir -p $(DESTDIR)$(mandir)/man3
-	mkdir -p $(DESTDIR)$(pkgconfigdir)
-	install -m644 $(LIB_STATIC) $(DESTDIR)$(usrlibdir)
-	install -m755 $(LIB_SHARED) $(DESTDIR)$(libdir)
-	for i in $(LIB_INCLUDES); do \
-	  install -m644 include/$$i $(DESTDIR)$(includedir)/$$i; \
-	done
-	install -m644 $(LIB_MANS) $(DESTDIR)$(mandir)/man3
-	install -m644 $(LIB_PKGCONFIG) $(DESTDIR)$(pkgconfigdir)
-	install -m644 $(LIB_PKGCONFIG_OVERLAY) $(DESTDIR)$(pkgconfigdir)
-ifeq ($(libdir),$(usrlibdir))
-	# If both dirs are the same, do a relative symlink.
-	ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
-else
-	# Otherwise, do an absolute one.
-	ln -sf $(libdir)/$(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
-endif
-	ln -sf $(LIB_SHARED) $(DESTDIR)$(libdir)/$(LIB_SONAME)
-
-.PHONY: clean
-clean:
-	rm -f $(LIB_PKGCONFIG)
-	rm -f $(LIB_PKGCONFIG_OVERLAY)
-	rm -f $(LIB_SRCS_GEN) $(LIB_MANS_GEN)
-	rm -f $(LIB_STATIC_OBJS)
-	rm -f $(LIB_STATIC)
-	rm -f $(LIB_SHARED_OBJS)
-	rm -f $(LIB_SHARED) $(LIB_SONAME) $(LIB_SHARED_SO)
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..4a6a326
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,19 @@
+## Process this file with automake to produce Makefile.in
+
+SUBDIRS = include man src
+
+ACLOCAL_AMFLAGS = -I m4
+
+EXTRA_DIST = \
+	autogen \
+	get-version \
+	$(nil)
+
+DISTCLEANFILES = ChangeLog
+.PHONY: ChangeLog
+
+ChangeLog:
+	git log --stat -C >$@
+
+dist-hook:
+	echo $(VERSION) >$(distdir)/.dist-version
diff --git a/autogen b/autogen
new file mode 100755
index 0000000..7cf1815
--- /dev/null
+++ b/autogen
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+mkdir -p m4
+autoreconf -f -i
+rm -rf autom4te.cache
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..b34b416
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,50 @@
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.67])
+AC_INIT([libbsd], m4_esyscmd([./get-version]), [libbsd at lists.freedesktop.org])
+AC_CONFIG_SRCDIR([src/fgetln.c])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE([1.8 foreign nostdinc])
+
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
+                            [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
+
+# Checks for operating system services and capabilities.
+AC_USE_SYSTEM_EXTENSIONS
+AC_SYS_LARGEFILE
+
+LT_INIT
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LN_S
+
+# Checks for libraries.
+
+# Checks for header files.
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_UID_T
+AC_C_INLINE
+AC_TYPE_INT64_T
+AC_TYPE_MODE_T
+AC_TYPE_OFF_T
+AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+
+# Checks for library functions.
+
+AC_CONFIG_FILES([
+	Makefile
+	include/Makefile
+	man/Makefile
+	src/Makefile
+	src/libbsd.pc
+	src/libbsd-overlay.pc
+])
+AC_CONFIG_HEADERS([config.h])
+AC_OUTPUT
diff --git a/get-version b/get-version
index 21f5dfd..591f593 100755
--- a/get-version
+++ b/get-version
@@ -44,4 +44,5 @@ else
   exit 1
 fi
 
-echo "$version"
+# Use printf to avoid the trailing new line that m4_esyscmd would not handle.
+printf "$version"
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..0201c28
--- /dev/null
+++ b/include/Makefile.am
@@ -0,0 +1,31 @@
+## Process this file with automake to produce Makefile.in
+
+nobase_include_HEADERS = \
+	bsd/sys/bitstring.h \
+	bsd/sys/cdefs.h \
+	bsd/sys/endian.h \
+	bsd/sys/poll.h \
+	bsd/sys/queue.h \
+	bsd/sys/tree.h \
+	bsd/netinet/ip_icmp.h \
+	bsd/bsd.h \
+	bsd/cdefs.h \
+	bsd/err.h \
+	bsd/getopt.h \
+	bsd/inet.h \
+	bsd/ip_icmp.h \
+	bsd/libutil.h \
+	bsd/md5.h \
+	bsd/nlist.h \
+	bsd/queue.h \
+	bsd/random.h \
+	bsd/readpassphrase.h \
+	bsd/stdio.h \
+	bsd/stdlib.h \
+	bsd/string.h \
+	bsd/unistd.h \
+	bsd/vis.h \
+	libutil.h \
+	nlist.h \
+	vis.h \
+	$(nil)
diff --git a/man/Makefile.am b/man/Makefile.am
new file mode 100644
index 0000000..129949a
--- /dev/null
+++ b/man/Makefile.am
@@ -0,0 +1,45 @@
+## Process this file with automake to produce Makefile.in
+
+EXTRA_DIST = \
+	mdX.3 \
+	$(nil)
+
+CLEANFILES = \
+	md5.3bsd \
+	$(nil)
+
+SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
+
+md5.3bsd: $(srcdir)/mdX.3
+	$(AM_V_GEN) sed $(SED_MD5_SUBST) $< > $@
+
+dist_man_MANS = \
+	arc4random.3 \
+	arc4random_addrandom.3 \
+	arc4random_buf.3 \
+	arc4random_stir.3 \
+	arc4random_uniform.3 \
+	dehumanize_number.3 \
+	fgetln.3 \
+	flopen.3 \
+	fmtcheck.3 \
+	getmode.3 \
+	getpeereid.3 \
+	heapsort.3 \
+	humanize_number.3 \
+	md5.3bsd \
+	mergesort.3 \
+	nlist.3 \
+	pidfile.3 \
+	radixsort.3 \
+	readpassphrase.3 \
+	reallocf.3 \
+	setmode.3 \
+	sradixsort.3 \
+	strlcat.3 \
+	strlcpy.3 \
+	strmode.3 \
+	strtonum.3 \
+	unvis.3 \
+	vis.3 \
+	$(nil)
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..9bd9257
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,85 @@
+## Process this file with automake to produce Makefile.in
+
+# Set default values for user variables
+CFLAGS = -Wall -Wextra -Wno-unused-variable
+
+AM_CPPFLAGS = \
+	-I$(top_builddir) \
+	-isystem $(top_srcdir)/include/bsd/ \
+	-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
+	-D_GNU_SOURCE -D__REENTRANT
+
+EXTRA_DIST = \
+	libbsd.map \
+	libbsd.pc.in \
+	libbsd-overlay.pc.in \
+	hash/helper.c \
+	$(nil)
+
+CLEANFILES = \
+	hash/md5hl.c \
+	$(nil)
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = \
+	libbsd.pc \
+	libbsd-overlay.pc \
+	$(nil)
+
+lib_LTLIBRARIES = libbsd.la
+
+hash/md5hl.c: $(srcdir)/hash/helper.c
+	$(MKDIR_P) hash
+	$(AM_V_GEN) sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
+
+libbsd_la_DEPENDENCIES = \
+	libbsd.map
+libbsd_la_LDFLAGS = \
+	-Wl,--version-script=$(srcdir)/libbsd.map \
+	-version-number 0:3:0
+libbsd_la_SOURCES = \
+	arc4random.c \
+	bsd_getopt.c \
+	dehumanize_number.c \
+	err.c \
+	fgetln.c \
+	flopen.c \
+	fmtcheck.c \
+	fpurge.c \
+	getpeereid.c \
+	hash/md5.c \
+	hash/md5hl.c \
+	heapsort.c \
+	humanize_number.c \
+	inet_net_pton.c \
+	local-elf.h \
+	merge.c \
+	nlist.c \
+	pidfile.c \
+	progname.c \
+	radixsort.c \
+	readpassphrase.c \
+	reallocf.c \
+	setmode.c \
+	setproctitle.c \
+	strlcat.c \
+	strlcpy.c \
+	strmode.c \
+	strtonum.c \
+	unvis.c \
+	vis.c \
+	$(nil)
+
+install-exec-hook:
+	if [ "$(libdir)" != "$(runtimelibdir)" ]; then \
+		mkdir -p $(DESTDIR)$(runtimelibdir); \
+		mv $(DESTDIR)$(libdir)/libbsd*.so.* \
+		   $(DESTDIR)$(runtimelibdir)/; \
+		soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \
+		sorelprefix=`echo $(libdir) | sed -r -e 's:(^/)?[^/]+:..:g'`; \
+		ln -sf $$sorelprefix$(runtimelibdir)/$$soname \
+		       $(DESTDIR)$(libdir)/libbsd.so; \
+	fi
+
+uninstall-hook:
+	rm -f $(DESTDIR)$(runtimelibdir)/libbsd*.so*
commit 0aa777f47e6ed96c963cc6de4aee7e78f8f9b07f
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Dec 31 07:35:52 2011 +0100

    Move .pc and .map files to src/

diff --git a/Makefile b/Makefile
index c359acb..ca7cb0e 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,8 @@ LIB_VERSION_MINOR := 3
 LIB_VERSION_MICRO := 0
 LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
 
-LIB_PKGCONFIG := $(LIB_NAME).pc
-LIB_PKGCONFIG_OVERLAY := $(LIB_NAME)-overlay.pc
+LIB_PKGCONFIG := src/$(LIB_NAME).pc
+LIB_PKGCONFIG_OVERLAY := src/$(LIB_NAME)-overlay.pc
 LIB_STATIC := $(LIB_NAME).a
 LIB_SHARED_SO := $(LIB_NAME).so
 LIB_SONAME := $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR)
@@ -184,7 +184,7 @@ $(LIB_SHARED): $(LIB_SHARED_OBJS)
 	$(LINK) \
 	  -shared \
 	  -Wl,-soname -Wl,$(LIB_SONAME) \
-	  -Wl,--version-script=libbsd.map \
+	  -Wl,--version-script=src/libbsd.map \
 	  -o $@ $^
 
 .PHONY: ChangeLog
diff --git a/libbsd-overlay.pc.in b/libbsd-overlay.pc.in
deleted file mode 100644
index 2bbb1e2..0000000
--- a/libbsd-overlay.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: libbsd
-Description: Utility functions from BSD systems (overlay)
-Version: @VERSION@
-URL: http://libbsd.freedesktop.org/
-Libs: -L${libdir} -lbsd
-Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY
diff --git a/libbsd.map b/libbsd.map
deleted file mode 100644
index 39e6ea9..0000000
--- a/libbsd.map
+++ /dev/null
@@ -1,91 +0,0 @@
-LIBBSD_0.0 {
-  global:
-    arc4random;
-    arc4random_stir;
-    arc4random_addrandom;
-
-    bsd_getopt;
-    optreset;
-
-    errc;
-    warnc;
-    verrc;
-    vwarnc;
-
-    fgetln;
-    fmtcheck;
-    heapsort;
-    humanize_number;
-
-    inet_net_pton; /* XXX: Already provided by glibc, remove. */
-
-    getprogname;
-    setprogname;
-
-    strlcpy;
-    strlcat;
-
-    setmode;
-    getmode;
-
-    vis;
-    strvis;
-    strvisx;
-    unvis;
-    strunvis;
-    strunvisx;
-
-    MD5Init;
-    MD5Update;
-    MD5Pad;
-    MD5Final;
-    MD5Transform;
-    MD5End;
-    MD5File;
-    MD5FileChunk;
-    MD5Data;
-
-  local:
-    *;
-};
-
-LIBBSD_0.1 {
-    strmode;
-
-    __fdnlist; /* Private symbol, but libkvm uses it. */
-    nlist;
-} LIBBSD_0.0;
-
-LIBBSD_0.2 {
-    strtonum;
-
-    strnvis;
-    strnunvis;
-
-    dehumanize_number;
-
-    readpassphrase;
-
-    flopen;
-
-    pidfile_open;
-    pidfile_write;
-    pidfile_close;
-    pidfile_remove;
-
-    setproctitle;
-
-    arc4random_buf;
-    arc4random_uniform;
-} LIBBSD_0.1;
-
-LIBBSD_0.3 {
-    reallocf;
-    getpeereid;
-
-    mergesort;
-    radixsort;
-    sradixsort;
-
-    fpurge;
-} LIBBSD_0.2;
diff --git a/libbsd.pc.in b/libbsd.pc.in
deleted file mode 100644
index 9f97323..0000000
--- a/libbsd.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: libbsd
-Description: Utility functions from BSD systems
-Version: @VERSION@
-URL: http://libbsd.freedesktop.org/
-Libs: -L${libdir} -lbsd
-Cflags: -I${includedir}
diff --git a/src/libbsd-overlay.pc.in b/src/libbsd-overlay.pc.in
new file mode 100644
index 0000000..2bbb1e2
--- /dev/null
+++ b/src/libbsd-overlay.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libbsd
+Description: Utility functions from BSD systems (overlay)
+Version: @VERSION@
+URL: http://libbsd.freedesktop.org/
+Libs: -L${libdir} -lbsd
+Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY
diff --git a/src/libbsd.map b/src/libbsd.map
new file mode 100644
index 0000000..39e6ea9
--- /dev/null
+++ b/src/libbsd.map
@@ -0,0 +1,91 @@
+LIBBSD_0.0 {
+  global:
+    arc4random;
+    arc4random_stir;
+    arc4random_addrandom;
+
+    bsd_getopt;
+    optreset;
+
+    errc;
+    warnc;
+    verrc;
+    vwarnc;
+
+    fgetln;
+    fmtcheck;
+    heapsort;
+    humanize_number;
+
+    inet_net_pton; /* XXX: Already provided by glibc, remove. */
+
+    getprogname;
+    setprogname;
+
+    strlcpy;
+    strlcat;
+
+    setmode;
+    getmode;
+
+    vis;
+    strvis;
+    strvisx;
+    unvis;
+    strunvis;
+    strunvisx;
+
+    MD5Init;
+    MD5Update;
+    MD5Pad;
+    MD5Final;
+    MD5Transform;
+    MD5End;
+    MD5File;
+    MD5FileChunk;
+    MD5Data;
+
+  local:
+    *;
+};
+
+LIBBSD_0.1 {
+    strmode;
+
+    __fdnlist; /* Private symbol, but libkvm uses it. */
+    nlist;
+} LIBBSD_0.0;
+
+LIBBSD_0.2 {
+    strtonum;
+
+    strnvis;
+    strnunvis;
+
+    dehumanize_number;
+
+    readpassphrase;
+
+    flopen;
+
+    pidfile_open;
+    pidfile_write;
+    pidfile_close;
+    pidfile_remove;
+
+    setproctitle;
+
+    arc4random_buf;
+    arc4random_uniform;
+} LIBBSD_0.1;
+
+LIBBSD_0.3 {
+    reallocf;
+    getpeereid;
+
+    mergesort;
+    radixsort;
+    sradixsort;
+
+    fpurge;
+} LIBBSD_0.2;
diff --git a/src/libbsd.pc.in b/src/libbsd.pc.in
new file mode 100644
index 0000000..9f97323
--- /dev/null
+++ b/src/libbsd.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libbsd
+Description: Utility functions from BSD systems
+Version: @VERSION@
+URL: http://libbsd.freedesktop.org/
+Libs: -L${libdir} -lbsd
+Cflags: -I${includedir}
commit 540ab03b1802bdad34999a5b5042d1b476588e39
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Dec 31 06:50:40 2011 +0100

    Move man pages to man/

diff --git a/Makefile b/Makefile
index 42b1bb0..c359acb 100644
--- a/Makefile
+++ b/Makefile
@@ -112,8 +112,8 @@ LIB_MANS := \
 	unvis.3 \
 	vis.3 \
 	$(LIB_MANS_GEN)
-LIB_MANS_GEN := $(patsubst %,src/%,$(LIB_MANS_GEN))
-LIB_MANS := $(patsubst %,src/%,$(LIB_MANS))
+LIB_MANS_GEN := $(patsubst %,man/%,$(LIB_MANS_GEN))
+LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
 
 LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o)
 LIB_SHARED_OBJS := $(LIB_SRCS:%.c=%.lo)
@@ -157,7 +157,7 @@ man: $(LIB_MANS)
 %.o: %.c
 	$(COMPILE) -o $@ -c $<
 
-src/md5.3bsd:  src/mdX.3
+man/md5.3bsd: man/mdX.3
 	sed -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g' $< > $@
 
 src/hash/md5hl.c: src/hash/helper.c
diff --git a/man/.gitignore b/man/.gitignore
new file mode 100644
index 0000000..ed4f453
--- /dev/null
+++ b/man/.gitignore
@@ -0,0 +1,2 @@
+md5.3
+md5.3bsd
diff --git a/man/arc4random.3 b/man/arc4random.3
new file mode 100644
index 0000000..eda74af
--- /dev/null
+++ b/man/arc4random.3
@@ -0,0 +1,128 @@
+.\" $OpenBSD: arc4random.3,v 1.2 1997/04/27 22:40:25 angelos Exp $
+.\" Copyright 1997 Niels Provos <provos at physnet.uni-hamburg.de>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"      This product includes software developed by Niels Provos.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" Manual page, using -mandoc macros
+.\" $FreeBSD$
+.\"
+.Dd April 15, 1997
+.Dt ARC4RANDOM 3
+.Os
+.Sh NAME
+.Nm arc4random ,
+.Nm arc4random_buf ,
+.Nm arc4random_uniform ,
+.Nm arc4random_stir ,
+.Nm arc4random_addrandom
+.Nd arc4 random number generator
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdlib.h
+.Ft u_int32_t
+.Fn arc4random "void"
+.Ft void
+.Fn arc4random_buf "void *buf" "size_t nbytes"
+.Ft u_int32_t
+.Fn arc4random_uniform "u_int32_t upper_bound"
+.Ft void
+.Fn arc4random_stir "void"
+.Ft void
+.Fn arc4random_addrandom "unsigned char *dat" "int datlen"
+.Sh DESCRIPTION
+The
+.Fn arc4random
+function uses the key stream generator employed by the
+arc4 cipher, which uses 8*8 8 bit S-Boxes.
+The S-Boxes
+can be in about
+.if t 2\u\s71700\s10\d
+.if n (2**1700)
+states.
+The
+.Fn arc4random
+function returns pseudo-random numbers in the range of 0 to
+.if t 2\u\s731\s10\d\(mi1,
+.if n (2**32)\(mi1,
+and therefore has twice the range of
+.Xr rand 3
+and
+.Xr random 3 .
+.Pp
+.Fn arc4random_buf
+function fills the region
+.Fa buf
+of length
+.Fa nbytes
+with ARC4-derived random data.
+.Pp
+.Fn arc4random_uniform
+will return a uniformly distributed random number less than
+.Fa upper_bound .
+.Fn arc4random_uniform
+is recommended over constructions like
+.Dq Li arc4random() % upper_bound
+as it avoids "modulo bias" when the upper bound is not a power of two.
+.Pp
+The
+.Fn arc4random_stir
+function reads data from
+.Pa /dev/urandom
+and uses it to permute the S-Boxes via
+.Fn arc4random_addrandom .
+.Pp
+There is no need to call
+.Fn arc4random_stir
+before using
+.Fn arc4random
+functions family, since
+they automatically initialize themselves.
+.Sh EXAMPLES
+The following produces a drop-in replacement for the traditional
+.Fn rand
+and
+.Fn random
+functions using
+.Fn arc4random :
+.Pp
+.Dl "#define foo4random() (arc4random() % ((unsigned)RAND_MAX + 1))"
+.Sh SEE ALSO
+.Xr rand 3 ,
+.Xr random 3 ,
+.Xr srandomdev 3
+.Sh HISTORY
+.Pa RC4
+has been designed by RSA Data Security, Inc.
+It was posted anonymously
+to the USENET and was confirmed to be equivalent by several sources who
+had access to the original cipher.
+Since
+.Pa RC4
+used to be a trade secret, the cipher is now referred to as
+.Pa ARC4 .
diff --git a/man/arc4random_addrandom.3 b/man/arc4random_addrandom.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/man/arc4random_addrandom.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/man/arc4random_buf.3 b/man/arc4random_buf.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/man/arc4random_buf.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/man/arc4random_stir.3 b/man/arc4random_stir.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/man/arc4random_stir.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/man/arc4random_uniform.3 b/man/arc4random_uniform.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/man/arc4random_uniform.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/man/dehumanize_number.3 b/man/dehumanize_number.3
new file mode 100644
index 0000000..7f5dcf3
--- /dev/null
+++ b/man/dehumanize_number.3
@@ -0,0 +1 @@
+.so man3/humanize_number.3
diff --git a/man/fgetln.3 b/man/fgetln.3
new file mode 100644
index 0000000..7dd3fc8
--- /dev/null
+++ b/man/fgetln.3
@@ -0,0 +1,125 @@
+.\" Copyright (c) 1990, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)fgetln.3	8.3 (Berkeley) 4/19/94
+.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
+.\"
+.Dd April 19, 1994
+.Dt FGETLN 3
+.Os
+.Sh NAME
+.Nm fgetln
+.Nd get a line from a stream
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdio.h
+.Ft char *
+.Fn fgetln "FILE *stream" "size_t *len"
+.Sh DESCRIPTION
+The
+.Fn fgetln
+function
+returns a pointer to the next line from the stream referenced by
+.Fa stream .
+This line is
+.Em not
+a C string as it does not end with a terminating
+.Dv NUL
+character.
+The length of the line, including the final newline,
+is stored in the memory location to which
+.Fa len
+points and is guaranteed to be greater than 0 upon successful completion.
+(Note, however, that if the line is the last
+in a file that does not end in a newline,
+the returned text will not contain a newline.)
+.Sh RETURN VALUES
+Upon successful completion a pointer is returned;
+this pointer becomes invalid after the next
+.Tn I/O
+operation on
+.Fa stream
+(whether successful or not)
+or as soon as the stream is closed.
+Otherwise,
+.Dv NULL
+is returned.
+The
+.Fn fgetln
+function
+does not distinguish between end-of-file and error; the routines
+.Xr feof 3
+and
+.Xr ferror 3
+must be used
+to determine which occurred.
+If an error occurs, the global variable
+.Va errno
+is set to indicate the error.
+The end-of-file condition is remembered, even on a terminal, and all
+subsequent attempts to read will return
+.Dv NULL
+until the condition is
+cleared with
+.Xr clearerr 3 .
+.Pp
+The text to which the returned pointer points may be modified,
+provided that no changes are made beyond the returned size.
+These changes are lost as soon as the pointer becomes invalid.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EBADF
+The argument
+.Fa stream
+is not a stream open for reading.
+.El
+.Pp
+The
+.Fn fgetln
+function
+may also fail and set
+.Va errno
+for any of the errors specified for the routines
+.Xr fflush 3 ,
+.Xr malloc 3 ,
+.Xr read 2 ,
+.Xr stat 2 ,
+or
+.Xr realloc 3 .
+.Sh SEE ALSO
+.Xr ferror 3 ,
+.Xr fgets 3 ,
+.Xr fgetwln 3 ,
+.Xr fopen 3 ,
+.Xr putc 3
+.Sh HISTORY
+The
+.Fn fgetln
+function first appeared in
+.Bx 4.4 .
diff --git a/man/flopen.3 b/man/flopen.3
new file mode 100644
index 0000000..8f81211
--- /dev/null
+++ b/man/flopen.3
@@ -0,0 +1,102 @@
+.\"-
+.\" Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd June 6, 2009
+.Dt FLOPEN 3
+.Os
+.Sh NAME
+.Nm flopen
+.Nd "Reliably open and lock a file"
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/fcntl.h
+.In bsd/libutil.h
+.Ft int
+.Fn flopen "const char *path" "int flags"
+.Ft int
+.Fn flopen "const char *path" "int flags" "mode_t mode"
+.Sh DESCRIPTION
+The
+.Fn flopen
+function opens or creates a file and acquires an exclusive lock on it.
+It is essentially equivalent with calling
+.Fn open
+with the same parameters followed by
+.Fn flock
+with an
+.Va operation
+argument of
+.Dv LOCK_EX ,
+except that
+.Fn flopen
+will attempt to detect and handle races that may occur between opening
+/ creating the file and locking it.
+Thus, it is well suited for opening lock files, PID files, spool
+files, mailboxes and other kinds of files which are used for
+synchronization between processes.
+.Pp
+If
+.Va flags
+includes
+.Dv O_NONBLOCK
+and the file is already locked,
+.Fn flopen
+will fail and set
+.Va errno
+to
+.Dv EWOULDBLOCK .
+.Pp
+As with
+.Fn open ,
+the additional
+.Va mode
+argument is required if
+.Va flags
+includes
+.Dv O_CREAT .
+.Sh RETURN VALUES
+If successful,
+.Fn flopen
+returns a valid file descriptor.
+Otherwise, it returns -1, and sets
+.Va errno
+as described in
+.Xr flock 2
+and
+.Xr open 2 .
+.Sh SEE ALSO
+.Xr errno 2 ,
+.Xr flock 2 ,
+.Xr open 2
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+function and this manual page were written by
+.An Dag-Erling Sm\(/orgrav Aq des at FreeBSD.org .
diff --git a/man/fmtcheck.3 b/man/fmtcheck.3
new file mode 100644
index 0000000..7bf5d39
--- /dev/null
+++ b/man/fmtcheck.3
@@ -0,0 +1,111 @@
+.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This file was contributed to The NetBSD Foundation by Allen Briggs.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/fmtcheck.3,v 1.9 2004/07/02 23:52:10 ru Exp $
+.Dd October 16, 2002
+.Os
+.Dt FMTCHECK 3
+.Sh NAME
+.Nm fmtcheck
+.Nd sanitizes user-supplied
+.Xr printf 3 Ns -style
+format string
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdio.h
+.Ft const char *
+.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
+.Sh DESCRIPTION
+The
+.Fn fmtcheck
+scans
+.Fa fmt_suspect
+and
+.Fa fmt_default
+to determine if
+.Fa fmt_suspect
+will consume the same argument types as
+.Fa fmt_default
+and to ensure that
+.Fa fmt_suspect
+is a valid format string.
+.Pp
+The
+.Xr printf 3
+family of functions cannot verify the types of arguments that they are
+passed at run-time.
+In some cases, like
+.Xr catgets 3 ,
+it is useful or necessary to use a user-supplied format string with no
+guarantee that the format string matches the specified arguments.
+.Pp
+The
+.Fn fmtcheck
+was designed to be used in these cases, as in:
+.Bd -literal -offset indent
+printf(fmtcheck(user_format, standard_format), arg1, arg2);
+.Ed
+.Pp
+In the check, field widths, fillers, precisions, etc.\& are ignored (unless
+the field width or precision is an asterisk
+.Ql *
+instead of a digit string).
+Also, any text other than the format specifiers
+is completely ignored.
+.Sh RETURN VALUES
+If
+.Fa fmt_suspect
+is a valid format and consumes the same argument types as
+.Fa fmt_default ,
+then the
+.Fn fmtcheck
+will return
+.Fa fmt_suspect .
+Otherwise, it will return
+.Fa fmt_default .
+.Sh SECURITY CONSIDERATIONS
+Note that the formats may be quite different as long as they accept the
+same arguments.
+For example,
+.Qq Li "%p %o %30s %#llx %-10.*e %n"
+is compatible with
+.Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" .
+However,
+.Qq Li %o
+is not equivalent to
+.Qq Li %lx
+because
+the first requires an integer and the second requires a long.
+.Sh SEE ALSO
+.Xr printf 3
+.Sh BUGS
+The
+.Fn fmtcheck
+function does not understand all of the conversions that
+.Xr printf 3
+does.
diff --git a/man/getmode.3 b/man/getmode.3
new file mode 100644
index 0000000..63315e7
--- /dev/null
+++ b/man/getmode.3
@@ -0,0 +1 @@
+.so man3/setmode.3
diff --git a/man/getpeereid.3 b/man/getpeereid.3
new file mode 100644
index 0000000..84c776e
--- /dev/null
+++ b/man/getpeereid.3
@@ -0,0 +1,138 @@
+.\"
+.\" Copyright (c) 2001 Dima Dorfman.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 15, 2001
+.Dt GETPEEREID 3
+.Os
+.Sh NAME
+.Nm getpeereid
+.Nd get the effective credentials of a UNIX-domain peer
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/types.h
+.In bsd/unistd.h
+.Ft int
+.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid"
+.Sh DESCRIPTION
+The
+.Fn getpeereid
+function returns the effective user and group IDs of the
+peer connected to a
+.Ux Ns -domain
+socket.
+The argument
+.Fa s
+must be a
+.Ux Ns -domain
+socket
+.Pq Xr unix 4
+of type
+.Dv SOCK_STREAM
+on which either
+.Xr connect 2
+or
+.Xr listen 2
+have been called.
+The effective used ID is placed in
+.Fa euid ,
+and the effective group ID in
+.Fa egid .
+.Pp
+The credentials returned to the
+.Xr listen 2
+caller are those of its peer at the time it called
+.Xr connect 2 ;
+the credentials returned to the
+.Xr connect 2
+caller are those of its peer at the time it called
+.Xr listen 2 .
+This mechanism is reliable; there is no way for either side to influence
+the credentials returned to its peer except by calling the appropriate
+system call (i.e., either
+.Xr connect 2
+or
+.Xr listen 2 )
+under different effective credentials.
+.Pp
+One common use of this routine is for a
+.Ux Ns -domain
+server
+to verify the credentials of its client.
+Likewise, the client can verify the credentials of the server.
+.Sh IMPLEMENTATION NOTES
+On
+.Fx ,
+.Fn getpeereid
+is implemented in terms of the
+.Dv LOCAL_PEERCRED
+.Xr unix 4
+socket option.
+.Sh RETURN VALUES
+.Rv -std getpeereid
+.Sh ERRORS
+The
+.Fn getpeereid
+function
+fails if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The argument
+.Fa s
+is not a valid descriptor.
+.It Bq Er ENOTSOCK
+The argument
+.Fa s
+is a file, not a socket.
+.It Bq Er ENOTCONN
+The argument
+.Fa s
+does not refer to a socket on which
+.Xr connect 2
+or
+.Xr listen 2
+have been called.
+.It Bq Er EINVAL
+The argument
+.Fa s
+does not refer to a socket of type
+.Dv SOCK_STREAM ,
+or the kernel returned invalid data.
+.El
+.Sh SEE ALSO
+.Xr connect 2 ,
+.Xr getpeername 2 ,
+.Xr getsockname 2 ,
+.Xr getsockopt 2 ,
+.Xr listen 2 ,
+.Xr unix 4
+.Sh HISTORY
+The
+.Fn getpeereid
+function appeared in
+.Fx 4.6 .
diff --git a/man/heapsort.3 b/man/heapsort.3
new file mode 100644
index 0000000..4261c84
--- /dev/null
+++ b/man/heapsort.3
@@ -0,0 +1,208 @@
+.\" Copyright (c) 1990, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
+.\" $FreeBSD$
+.\"
+.Dd September 30, 2003
+.Dt QSORT 3
+.Os
+.Sh NAME
+.Nm heapsort , mergesort
+.Nd sort functions
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdlib.h
+.Ft int
+.Fo heapsort
+.Fa "void *base"
+.Fa "size_t nmemb"
+.Fa "size_t size"
+.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
+.Fc
+.Ft int
+.Fo mergesort
+.Fa "void *base"
+.Fa "size_t nmemb"
+.Fa "size_t size"
+.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn heapsort
+function is a modified selection sort.
+The
+.Fn mergesort
+function is a modified merge sort with exponential search
+intended for sorting data with pre-existing order.
+.Pp
+The
+.Fn heapsort
+function sorts an array of
+.Fa nmemb
+objects, the initial member of which is pointed to by
+.Fa base .
+The size of each object is specified by
+.Fa size .
+The
+.Fn mergesort
+function
+behaves similarly, but
+.Em requires
+that
+.Fa size
+be greater than
+.Dq "sizeof(void *) / 2" .
+.Pp
+The contents of the array
+.Fa base
+are sorted in ascending order according to
+a comparison function pointed to by
+.Fa compar ,
+which requires two arguments pointing to the objects being
+compared.
+.Pp
+The comparison function must return an integer less than, equal to, or
+greater than zero if the first argument is considered to be respectively
+less than, equal to, or greater than the second.
+.Pp
+The algorithm implemented by
+.Fn heapsort
+is
+.Em not
+stable, that is, if two members compare as equal, their order in
+the sorted array is undefined.
+The
+.Fn mergesort
+algorithm is stable.
+.Pp
+The
+.Fn heapsort
+function is an implementation of
+.An "J.W.J. William" Ns 's
+.Dq heapsort
+algorithm,
+a variant of selection sorting; in particular, see
+.An "D.E. Knuth" Ns 's
+.%T "Algorithm H" .
+.Sy Heapsort
+takes O N lg N worst-case time.
+Its
+.Em only
+advantage over
+.Fn qsort
+is that it uses almost no additional memory; while
+.Fn qsort
+does not allocate memory, it is implemented using recursion.
+.Pp
+The function
+.Fn mergesort
+requires additional memory of size
+.Fa nmemb *
+.Fa size
+bytes; it should be used only when space is not at a premium.
+The
+.Fn mergesort
+function
+is optimized for data with pre-existing order; its worst case
+time is O N lg N; its best case is O N.
+.Pp
+Normally,
+.Fn qsort
+is faster than
+.Fn mergesort
+is faster than
+.Fn heapsort .
+Memory availability and pre-existing order in the data can make this
+untrue.
+.Sh RETURN VALUES
+.Rv -std heapsort mergesort
+.Sh ERRORS
+The
+.Fn heapsort
+and
+.Fn mergesort
+functions succeed unless:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa size
+argument is zero, or,
+the
+.Fa size
+argument to
+.Fn mergesort
+is less than
+.Dq "sizeof(void *) / 2" .
+.It Bq Er ENOMEM
+The
+.Fn heapsort
+or
+.Fn mergesort
+functions
+were unable to allocate memory.
+.El
+.Sh SEE ALSO
+.Xr sort 1 ,
+.Xr radixsort 3
+.Rs
+.%A Williams, J.W.J
+.%D 1964
+.%T "Heapsort"
+.%J "Communications of the ACM"
+.%V 7:1
+.%P pp. 347-348
+.Re
+.Rs
+.%A Knuth, D.E.
+.%D 1968
+.%B "The Art of Computer Programming"
+.%V Vol. 3
+.%T "Sorting and Searching"
+.%P pp. 114-123, 145-149
+.Re
+.Rs
+.%A McIlroy, P.M.
+.%T "Optimistic Sorting and Information Theoretic Complexity"
+.%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms"
+.%V January 1992
+.Re
+.Rs
+.%A Bentley, J.L.
+.%A McIlroy, M.D.
+.%T "Engineering a Sort Function"
+.%J "Software--Practice and Experience"
+.%V Vol. 23(11)
+.%P pp. 1249-1265
+.%D November\ 1993
+.Re
diff --git a/man/humanize_number.3 b/man/humanize_number.3
new file mode 100644
index 0000000..e0ffdf0
--- /dev/null
+++ b/man/humanize_number.3
@@ -0,0 +1,171 @@
+.\"	$NetBSD: humanize_number.3,v 1.8 2008/04/30 13:10:50 martin Exp $
+.\"
+.\" Copyright (c) 1999, 2002, 2008 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Luke Mewburn and by Tomas Svensson.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd February 9, 2008
+.Dt HUMANIZE_NUMBER 3
+.Os
+.Sh NAME
+.Nm dehumanize_number ,
+.Nm humanize_number
+.Nd format a number into a human readable form and viceversa
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdlib.h
+.Ft int
+.Fn dehumanize_number "const char *str" "int64_t *result"
+.Ft int
+.Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags"
+.Sh DESCRIPTION
+The
+.Fn humanize_number
+function formats the signed 64 bit quantity given in
+.Fa number
+into
+.Fa buffer .
+A space and then
+.Fa suffix
+is appended to the end.
+.Fa buffer
+must be at least
+.Fa len
+bytes long.
+.Pp
+If the formatted number (including
+.Fa suffix )
+would be too long to fit into
+.Fa buffer ,
+then divide
+.Fa number
+by 1024 until it will.
+In this case, prefix
+.Fa suffix
+with the appropriate SI designator.
+.Pp
+The prefixes are:
+.Bl -column "Prefix" "Description" "Multiplier" -offset indent
+.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
+.It k	kilo	1024
+.It M	mega	1048576
+.It G	giga	1073741824
+.It T	tera	1099511627776
+.It P	peta	1125899906842624
+.It E	exa	1152921504606846976
+.El
+.Pp
+.Fa len
+must be at least 4 plus the length of
+.Fa suffix ,
+in order to ensure a useful result is generated into
+.Fa buffer .
+To use a specific prefix, specify this as
+.Fa scale
+(Multiplier = 1024 ^ scale).
+This can not be combined with any of the
+.Fa scale
+flags below.
+.Pp
+The following flags may be passed in
+.Pa scale :
+.Bl -tag -width Dv -offset indent
+.It Dv HN_AUTOSCALE
+Format the buffer using the lowest multiplier possible.
+.It Dv HN_GETSCALE
+Return the prefix index number (the number of times
+.Fa number
+must be divided to fit) instead of formatting it to the buffer.
+.El
+.Pp
+The following flags may be passed in
+.Pa flags :
+.Bl -tag -width Dv -offset indent
+.It Dv HN_DECIMAL
+If the final result is less than 10, display it using one digit.
+.It Dv HN_NOSPACE
+Do not put a space between
+.Fa number
+and the prefix.
+.It Dv HN_B
+Use 'B' (bytes) as prefix if the original result does not have a prefix.
+.It Dv HN_DIVISOR_1000
+Divide
+.Fa number
+with 1000 instead of 1024.
+.El
+.Pp
+The
+.Fn dehumanize_number
+function parses the string representing an integral value given in
+.Fa str
+and stores the numerical value in the integer pointed to by
+.Fa result .
+The provided string may hold one of the suffixes, which will be interpreted
+and used to scale up its accompanying numerical value.
+.Sh RETURN VALUES
+.Fn humanize_number
+returns the number of characters stored in
+.Fa buffer
+(excluding the terminating NUL) upon success, or \-1 upon failure.
+If
+.Dv HN_GETSCALE
+is specified, the prefix index number will be returned instead.
+.Pp
+.Fn dehumanize_number
+returns 0 if the string was parsed correctly.
+A \-1 is returned to indicate failure and an error code is stored in
+.Va errno .
+.Sh ERRORS
+.Fn dehumanize_number
+will fail and no number will be stored in
+.Fa result
+if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The string in
+.Fa str
+was empty or carried an unknown suffix.
+.It Bq Er ERANGE
+The string in
+.Fa str
+represented a number that does not fit in
+.Fa result .
+.El
+.Sh SEE ALSO
+.Xr humanize_number 9
+.Sh HISTORY
+.Fn humanize_number
+first appeared in
+.Nx 2.0 .
+.Pp
+.Fn dehumanize_number
+first appeared in
+.\" FIXME: This should be in groff, but for now it avoids the warning.
+.ds operating-system-NetBSD-5.0 5.0
+.Nx 5.0 .
diff --git a/man/mdX.3 b/man/mdX.3
new file mode 100644
index 0000000..41bf329
--- /dev/null
+++ b/man/mdX.3
@@ -0,0 +1,226 @@
+.\"
+.\" ----------------------------------------------------------------------------
+.\" "THE BEER-WARE LICENSE" (Revision 42):
+.\" <phk at login.dkuug.dk> wrote this file.  As long as you retain this notice you
+.\" can do whatever you want with this stuff. If we meet some day, and you think
+.\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+.\" ----------------------------------------------------------------------------
+.\"
+.\" 	$MirOS: src/lib/libc/hash/mdX.3,v 1.4 2007/05/07 16:15:56 tg Exp $
+.\" 	$OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $
+.\"
+.Dd April 29, 2004
+.Dt MDX 3
+.Os
+.Sh NAME
+.Nm MDXInit ,
+.Nm MDXUpdate ,
+.Nm MDXPad ,
+.Nm MDXFinal ,
+.Nm MDXTransform ,
+.Nm MDXEnd ,
+.Nm MDXFile ,
+.Nm MDXFileChunk ,
+.Nm MDXData
+.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <bsd/mdX.h>
+.Ft void
+.Fn MDXInit "MDX_CTX *context"
+.Ft void
+.Fn MDXUpdate "MDX_CTX *context" "const u_int8_t *data" "size_t len"
+.Ft void
+.Fn MDXPad "MDX_CTX *context"
+.Ft void
+.Fn MDXFinal "u_int8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context"
+.Ft void
+.Fn MDXTransform "u_int32_t state[4]" "u_int8_t block[MDX_BLOCK_LENGTH]"
+.Ft "char *"
+.Fn MDXEnd "MDX_CTX *context" "char *buf"
+.Ft "char *"
+.Fn MDXFile "const char *filename" "char *buf"
+.Ft "char *"
+.Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
+.Ft "char *"
+.Fn MDXData "const u_int8_t *data" "size_t len" "char *buf"
+.Sh DESCRIPTION
+The MDX functions calculate a 128-bit cryptographic checksum (digest)
+for any number of input bytes.
+A cryptographic checksum is a one-way
+hash-function, that is, you cannot find (except by exhaustive search)
+the input corresponding to a particular output.
+This net result is a
+.Dq fingerprint
+of the input-data, which doesn't disclose the actual input.
+.Pp
+MD4 has been broken; it should only be used where necessary for
+backward compatibility.
+MD5 has not yet (1999-02-11) been broken, but recent attacks have cast
+some doubt on its security properties.
+The attacks on both MD4 and MD5
+are both in the nature of finding
+.Dq collisions
+\- that is, multiple
+inputs which hash to the same value; it is still unlikely for an attacker
+to be able to determine the exact original input given a hash value.
+.Pp
+The
+.Fn MDXInit ,
+.Fn MDXUpdate ,
+and
+.Fn MDXFinal
+functions are the core functions.
+Allocate an MDX_CTX, initialize it with
+.Fn MDXInit ,
+run over the data with
+.Fn MDXUpdate ,
+and finally extract the result using
+.Fn MDXFinal .
+.Pp
+The
+.Fn MDXPad
+function can be used to apply padding to the message digest as in
+.Fn MDXFinal ,
+but the current context can still be used with
+.Fn MDXUpdate .
+.Pp
+The
+.Fn MDXTransform
+function is used by
+.Fn MDXUpdate
+to hash 512-bit blocks and forms the core of the algorithm.
+Most programs should use the interface provided by
+.Fn MDXInit ,
+.Fn MDXUpdate
+and
+.Fn MDXFinal
+instead of calling
+.Fn MDXTransform
+directly.
+.Pp
+.Fn MDXEnd
+is a wrapper for
+.Fn MDXFinal
+which converts the return value to an MDX_DIGEST_STRING_LENGTH-character
+(including the terminating '\e0')
+.Tn ASCII
+string which represents the 128 bits in hexadecimal.
+.Pp
+.Fn MDXFile
+calculates the digest of a file, and uses
+.Fn MDXEnd
+to return the result.
+If the file cannot be opened, a null pointer is returned.
+.Pp
+.Fn MDXFileChunk
+behaves like
+.Fn MDXFile
+but calculates the digest only for that portion of the file starting at
+.Fa offset
+and continuing for
+.Fa length
+bytes or until end of file is reached, whichever comes first.
+A zero
+.Fa length
+can be specified to read until end of file.
+A negative
+.Fa length
+or
+.Fa offset
+will be ignored.
+.Fn MDXData
+calculates the digest of a chunk of data in memory, and uses
+.Fn MDXEnd
+to return the result.
+.Pp
+When using
+.Fn MDXEnd ,
+.Fn MDXFile ,
+.Fn MDXFileChunk ,
+or
+.Fn MDXData ,
+the
+.Ar buf
+argument can be a null pointer, in which case the returned string
+is allocated with
+.Xr malloc 3
+and subsequently must be explicitly deallocated using
+.Xr free 3
+after use.
+If the
+.Ar buf
+argument is non-null it must point to at least MDX_DIGEST_STRING_LENGTH
+characters of buffer space.
+.Sh SEE ALSO
+.Xr cksum 1 ,
+.Xr md5 1 ,
+.Xr adler32 3 ,
+.Xr mdY 3 ,
+.Xr rmd160 3 ,
+.Xr sfv 3 ,
+.Xr sha1 3 ,
+.Xr sha2 3 ,
+.Xr suma 3 ,
+.Xr tiger 3 ,
+.Xr whirlpool 3
+.Rs
+.%A R. Rivest
+.%T The MD4 Message-Digest Algorithm
+.%O RFC 1186
+.Re
+.Rs
+.%A R. Rivest
+.%T The MD5 Message-Digest Algorithm
+.%O RFC 1321
+.Re
+.Rs
+.%A RSA Laboratories
+.%T Frequently Asked Questions About today's Cryptography
+.%O \&<http://www.rsa.com/rsalabs/faq/>
+.Re
+.Rs
+.%A H. Dobbertin
+.%T Alf Swindles Ann
+.%J CryptoBytes
+.%N 1(3):5
+.%D 1995
+.Re
+.Rs
+.%A MJ. B. Robshaw
+.%T On Recent Results for MD4 and MD5
+.%J RSA Laboratories Bulletin
+.%N 4
+.%D November 12, 1996
+.Re
+.Rs
+.%A Hans Dobbertin
+.%T Cryptanalysis of MD5 Compress
+.Re
+.Sh HISTORY
+These functions appeared in
+.Ox 2.0 .
+.Sh AUTHORS
+The original MDX routines were developed by
+.Tn RSA
+Data Security, Inc., and published in the above references.
+This code is derived from a public domain implementation written by Colin Plumb.
+.Pp
+The
+.Fn MDXEnd ,
+.Fn MDXFile ,
+.Fn MDXFileChunk ,
+and
+.Fn MDXData
+helper functions are derived from code written by Poul-Henning Kamp.
+.Sh BUGS
+Collisions have been found for the full versions of both MD4 and MD5
+as well as strong attacks against the SHA-0 and SHA-1 family.
+The use of
+.Xr sha2 3 ,
+or
+.Xr rmd160 3
+is recommended instead.
diff --git a/man/mergesort.3 b/man/mergesort.3
new file mode 100644
index 0000000..c1979c3
--- /dev/null
+++ b/man/mergesort.3
@@ -0,0 +1 @@
+.so man3/heapsort.3
diff --git a/man/nlist.3 b/man/nlist.3
new file mode 100644
index 0000000..25624c7
--- /dev/null
+++ b/man/nlist.3
@@ -0,0 +1,78 @@
+.\" Copyright (c) 1980, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)nlist.3	8.3 (Berkeley) 4/19/94
+.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
+.\"
+.Dd April 19, 1994
+.Dt NLIST 3
+.Os
+.Sh NAME
+.Nm nlist
+.Nd retrieve symbol table name list from an executable file
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/nlist.h
+.Ft int
+.Fn nlist "const char *filename" "struct nlist *nl"
+.Sh DESCRIPTION
+The
+.Fn nlist
+function
+retrieves name list entries from the symbol table of an
+executable file (see
+.Xr a.out 5 ) .
+The argument
+.Fa \&nl
+is set to reference the
+beginning of the list.
+The list is preened of binary and invalid data;
+if an entry in the
+name list is valid, the
+.Fa n_type
+and
+.Fa n_value
+for the entry are copied into the list
+referenced by
+.Fa \&nl .
+No other data is copied.
+The last entry in the list is always
+.Dv NULL .
+.Sh RETURN VALUES
+The number of invalid entries is returned if successful; otherwise,
+if the file
+.Fa filename
+does not exist or is not executable, the returned value is \-1.
+.Sh SEE ALSO
+.Xr a.out 5
+.Sh HISTORY
+A
+.Fn nlist
+function appeared in
+.At v6 .
diff --git a/man/pidfile.3 b/man/pidfile.3
new file mode 100644
index 0000000..2f84c44
--- /dev/null
+++ b/man/pidfile.3
@@ -0,0 +1,254 @@
+.\" Copyright (c) 2005 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd October 20, 2008
+.Dt PIDFILE 3
+.Os
+.Sh NAME
+.Nm pidfile_open ,
+.Nm pidfile_write ,
+.Nm pidfile_close ,
+.Nm pidfile_remove
+.Nd "library for PID files handling"
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/libutil.h
+.Ft "struct pidfh *"
+.Fn pidfile_open "const char *path" "mode_t mode" "pid_t *pidptr"
+.Ft int
+.Fn pidfile_write "struct pidfh *pfh"
+.Ft int
+.Fn pidfile_close "struct pidfh *pfh"
+.Ft int
+.Fn pidfile_remove "struct pidfh *pfh"
+.Sh DESCRIPTION
+The
+.Nm pidfile
+family of functions allows daemons to handle PID files.
+It uses
+.Xr flopen 3
+to lock a pidfile and detect already running daemons.
+.Pp
+The
+.Fn pidfile_open
+function opens (or creates) a file specified by the
+.Fa path
+argument and locks it.
+If a file can not be locked, a PID of an already running daemon is returned in
+the
+.Fa pidptr
+argument (if it is not
+.Dv NULL ) .
+The function does not write process' PID into the file here, so it can be
+used before
+.Fn fork Ns ing
+and exit with a proper error message when needed.
+If the
+.Fa path
+argument is
+.Dv NULL ,
+.Pa /var/run/ Ns Ao Va progname Ac Ns Pa .pid
+file will be used.
+.Pp
+The
+.Fn pidfile_write
+function writes process' PID into a previously opened file.
+.Pp
+The
+.Fn pidfile_close
+function closes a pidfile.
+It should be used after daemon
+.Fn fork Ns s
+to start a child process.
+.Pp
+The
+.Fn pidfile_remove
+function closes and removes a pidfile.
+.Sh RETURN VALUES
+The
+.Fn pidfile_open
+function returns a valid pointer to a
+.Vt pidfh
+structure on success, or
+.Dv NULL
+if an error occurs.
+If an error occurs,
+.Va errno
+will be set.
+.Pp
+.Rv -std pidfile_write pidfile_close pidfile_remove
+.Sh EXAMPLES
+The following example shows in which order these functions should be used.
+Note that it is safe to pass
+.Dv NULL
+to
+.Fn pidfile_write ,
+.Fn pidfile_remove
+and
+.Fn pidfile_close
+functions.
+.Bd -literal
+struct pidfh *pfh;
+pid_t otherpid, childpid;
+
+pfh = pidfile_open("/var/run/daemon.pid", 0600, &otherpid);
+if (pfh == NULL) {
+	if (errno == EEXIST) {
+		errx(EXIT_FAILURE, "Daemon already running, pid: %jd.",
+		    (intmax_t)otherpid);
+	}
+	/* If we cannot create pidfile from other reasons, only warn. */
+	warn("Cannot open or create pidfile");
+}
+
+if (daemon(0, 0) == -1) {
+	warn("Cannot daemonize");
+	pidfile_remove(pfh);
+	exit(EXIT_FAILURE);
+}
+
+pidfile_write(pfh);
+
+for (;;) {
+	/* Do work. */
+	childpid = fork();
+	switch (childpid) {
+	case -1:
+		syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno));
+		break;
+	case 0:
+		pidfile_close(pfh);
+		/* Do child work. */
+		break;
+	default:
+		syslog(LOG_INFO, "Child %jd started.", (intmax_t)childpid);
+		break;
+	}
+}
+
+pidfile_remove(pfh);
+exit(EXIT_SUCCESS);
+.Ed
+.Sh ERRORS
+The
+.Fn pidfile_open
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EEXIST
+Some process already holds the lock on the given pidfile, meaning that a
+daemon is already running.
+.It Bq Er ENAMETOOLONG
+Specified pidfile's name is too long.
+.It Bq Er EINVAL
+Some process already holds the lock on the given pidfile, but PID read
+from there is invalid.
+.It Bq Er EAGAIN
+Some process already holds the lock on the given pidfile, but the file
+is truncated.
+Most likely, the existing daemon is writing new PID into
+the file.
+.El
+.Pp
+The
+.Fn pidfile_open
+function may also fail and set
+.Va errno
+for any errors specified for the
+.Xr fstat 2 ,
+.Xr open 2 ,
+and
+.Xr read 2
+calls.
+.Pp
+The
+.Fn pidfile_write
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Improper function use.
+Probably called before
+.Fn pidfile_open .
+.El
+.Pp
+The
+.Fn pidfile_write
+function may also fail and set
+.Va errno
+for any errors specified for the
+.Xr fstat 2 ,
+.Xr ftruncate 2 ,
+and
+.Xr write 2
+calls.
+.Pp
+The
+.Fn pidfile_close
+function may fail and set
+.Va errno
+for any errors specified for the
+.Xr close 2
+and
+.Xr fstat 2
+calls.
+.Pp
+The
+.Fn pidfile_remove
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Improper function use.
+Probably called not from the process which made
+.Fn pidfile_write .
+.El
+.Pp
+The
+.Fn pidfile_remove
+function may also fail and set
+.Va errno
+for any errors specified for the
+.Xr close 2 ,
+.Xr fstat 2 ,
+.Xr write 2 ,
+and
+.Xr unlink 2
+system calls and the
+.Xr flopen 3
+library function.
+.Sh SEE ALSO
+.Xr open 2 ,
+.Xr daemon 3 ,
+.Xr flopen 3
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm pidfile
+functionality is based on ideas from
+.An John-Mark Gurney Aq jmg at FreeBSD.org .
+.Pp
+The code and manual page was written by
+.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org .
diff --git a/man/radixsort.3 b/man/radixsort.3
new file mode 100644
index 0000000..3884124
--- /dev/null
+++ b/man/radixsort.3
@@ -0,0 +1,161 @@
+.\" Copyright (c) 1990, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)radixsort.3	8.2 (Berkeley) 1/27/94
+.\" $FreeBSD$
+.\"
+.Dd January 27, 1994
+.Dt RADIXSORT 3
+.Os
+.Sh NAME
+.Nm radixsort , sradixsort
+.Nd radix sort
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In limits.h
+.In bsd/stdlib.h
+.Ft int
+.Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
+.Ft int
+.Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
+.Sh DESCRIPTION
+The
+.Fn radixsort
+and
+.Fn sradixsort
+functions
+are implementations of radix sort.
+.Pp
+These functions sort an array of pointers to byte strings, the initial
+member of which is referenced by
+.Fa base .
+The byte strings may contain any values; the end of each string
+is denoted by the user-specified value
+.Fa endbyte .
+.Pp
+Applications may specify a sort order by providing the
+.Fa table
+argument.
+If
+.Pf non- Dv NULL ,
+.Fa table
+must reference an array of
+.Dv UCHAR_MAX
++ 1 bytes which contains the sort
+weight of each possible byte value.
+The end-of-string byte must have a sort weight of 0 or 255
+(for sorting in reverse order).
+More than one byte may have the same sort weight.
+The
+.Fa table
+argument
+is useful for applications which wish to sort different characters
+equally, for example, providing a table with the same weights
+for A-Z as for a-z will result in a case-insensitive sort.
+If
+.Fa table
+is NULL, the contents of the array are sorted in ascending order
+according to the
+.Tn ASCII
+order of the byte strings they reference and
+.Fa endbyte
+has a sorting weight of 0.
+.Pp
+The
+.Fn sradixsort
+function is stable, that is, if two elements compare as equal, their
+order in the sorted array is unchanged.
+The
+.Fn sradixsort
+function uses additional memory sufficient to hold
+.Fa nmemb
+pointers.
+.Pp
+The
+.Fn radixsort
+function is not stable, but uses no additional memory.
+.Pp
+These functions are variants of most-significant-byte radix sorting; in
+particular, see
+.An "D.E. Knuth" Ns 's
+.%T "Algorithm R"
+and section 5.2.5, exercise 10.
+They take linear time relative to the number of bytes in the strings.
+.Sh RETURN VALUES
+.Rv -std radixsort
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The value of the
+.Fa endbyte
+element of
+.Fa table
+is not 0 or 255.
+.El
+.Pp
+Additionally, the
+.Fn sradixsort
+function
+may fail and set
+.Va errno
+for any of the errors specified for the library routine
+.Xr malloc 3 .
+.Sh SEE ALSO
+.Xr sort 1 ,
+.Xr qsort 3
+.Pp
+.Rs
+.%A Knuth, D.E.
+.%D 1968
+.%B "The Art of Computer Programming"
+.%T "Sorting and Searching"
+.%V Vol. 3
+.%P pp. 170-178
+.Re
+.Rs
+.%A Paige, R.
+.%D 1987
+.%T "Three Partition Refinement Algorithms"
+.%J "SIAM J. Comput."
+.%V Vol. 16
+.%N No. 6
+.Re
+.Rs
+.%A McIlroy, P.
+.%D 1993
+.%B "Engineering Radix Sort"
+.%T "Computing Systems"
+.%V Vol. 6:1
+.%P pp. 5-27
+.Re
+.Sh HISTORY
+The
+.Fn radixsort
+function first appeared in
+.Bx 4.4 .
diff --git a/man/readpassphrase.3 b/man/readpassphrase.3
new file mode 100644
index 0000000..967f8d3
--- /dev/null
+++ b/man/readpassphrase.3
@@ -0,0 +1,168 @@
+.\"	$OpenBSD: readpassphrase.3,v 1.16 2005/07/22 03:16:58 jaredy Exp $
+.\"
+.\" Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller at courtesan.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\" Sponsored in part by the Defense Advanced Research Projects
+.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
+.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
+.\"
+.Dd $Mdocdate: May 31 2007 $
+.Dt READPASSPHRASE 3
+.Os
+.Sh NAME
+.Nm readpassphrase
+.Nd get a passphrase from the user
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.Fd #include <bsd/readpassphrase.h>
+.Ft char *
+.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
+.Sh DESCRIPTION
+The
+.Fn readpassphrase
+function displays a prompt to, and reads in a passphrase from,
+.Pa /dev/tty .
+If this file is inaccessible
+and the
+.Dv RPP_REQUIRE_TTY
+flag is not set,
+.Fn readpassphrase
+displays the prompt on the standard error output and reads from the standard
+input.
+In this case it is generally not possible to turn off echo.
+.Pp
+Up to
+.Fa bufsiz
+- 1 characters (one is for the NUL) are read into the provided buffer
+.Fa buf .
+Any additional
+characters and the terminating newline (or return) character are discarded.
+.Pp
+.Fn readpassphrase
+takes the following optional
+.Fa flags :
+.Bd -literal -offset indent
+RPP_ECHO_OFF		turn off echo (default behavior)
+RPP_ECHO_ON		leave echo on
+RPP_REQUIRE_TTY		fail if there is no tty
+RPP_FORCELOWER		force input to lower case
+RPP_FORCEUPPER		force input to upper case
+RPP_SEVENBIT		strip the high bit from input
+RPP_STDIN		force read of passphrase from stdin
+.Ed
+.Pp
+The calling process should zero the passphrase as soon as possible to
+avoid leaving the cleartext passphrase visible in the process's address
+space.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn readpassphrase
+returns a pointer to the NUL-terminated passphrase.
+If an error is encountered, the terminal state is restored and
+a null pointer is returned.
+.Sh FILES
+.Bl -tag -width /dev/tty -compact
+.It Pa /dev/tty
+.El
+.Sh EXAMPLES
+The following code fragment will read a passphrase from
+.Pa /dev/tty
+into the buffer
+.Fa passbuf .
+.Bd -literal -offset indent
+char passbuf[1024];
+
+\&...
+
+if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
+    RPP_REQUIRE_TTY) == NULL)
+	errx(1, "unable to read passphrase");
+
+if (compare(transform(passbuf), epass) != 0)
+	errx(1, "bad passphrase");
+
+\&...
+
+memset(passbuf, 0, sizeof(passbuf));
+.Ed
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EINTR
+The
+.Fn readpassphrase
+function was interrupted by a signal.
+.It Bq Er EINVAL
+The
+.Ar bufsiz
+argument was zero.
+.It Bq Er EIO
+The process is a member of a background process attempting to read
+from its controlling terminal, the process is ignoring or blocking
+the
+.Dv SIGTTIN
+signal, or the process group is orphaned.
+.It Bq Er EMFILE
+The process has already reached its limit for open file descriptors.
+.It Bq Er ENFILE
+The system file table is full.
+.It Bq Er ENOTTY
+There is no controlling terminal and the
+.Dv RPP_REQUIRE_TTY
+flag was specified.
+.El
+.Sh SIGNALS
+.Fn readpassphrase
+will catch the following signals:
+.Bd -literal -offset indent
+SIGALRM		SIGHUP		SIGINT
+SIGPIPE		SIGQUIT		SIGTERM
+SIGTSTP		SIGTTIN		SIGTTOU
+.Ed
+.Pp
+When one of the above signals is intercepted, terminal echo will
+be restored if it had previously been turned off.
+If a signal handler was installed for the signal when
+.Fn readpassphrase
+was called, that handler is then executed.
+If no handler was previously installed for the signal then the
+default action is taken as per
+.Xr sigaction 2 .
+.Pp
+The
+.Dv SIGTSTP ,
+.Dv SIGTTIN ,
+and
+.Dv SIGTTOU
+signals (stop signals generated from keyboard or due to terminal I/O
+from a background process) are treated specially.
+When the process is resumed after it has been stopped,
+.Fn readpassphrase
+will reprint the prompt and the user may then enter a passphrase.
+.Sh SEE ALSO
+.Xr sigaction 2 ,
+.Xr getpass 3
+.Sh STANDARDS
+The
+.Fn readpassphrase
+function is an
+.Ox
+extension and should not be used if portability is desired.
+.Sh HISTORY
+The
+.Fn readpassphrase
+function first appeared in
+.Ox 2.9 .
diff --git a/man/reallocf.3 b/man/reallocf.3
new file mode 100644
index 0000000..99152b6
--- /dev/null
+++ b/man/reallocf.3
@@ -0,0 +1,107 @@
+.\" Copyright (c) 1980, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)malloc.3	8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
+.\"
+.Dd September 26, 2009
+.Dt MALLOC 3
+.Os
+.Sh NAME
+.Nm reallocf
+.Nd general purpose memory allocation functions
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/stdlib.h
+.Ft void *
+.Fn reallocf "void *ptr" "size_t size"
+.Sh DESCRIPTION
+The
+.Fn reallocf
+function changes the size of the previously allocated memory referenced by
+.Fa ptr
+to
+.Fa size
+bytes.
+The contents of the memory are unchanged up to the lesser of the new and
+old sizes.
+If the new size is larger,
+the contents of the newly allocated portion of the memory are undefined.
+Upon success, the memory referenced by
+.Fa ptr
+is freed and a pointer to the newly allocated memory is returned.
+Note that
+.Fn reallocf
+may move the memory allocation, resulting in a different return value than
+.Fa ptr .
+If
+.Fa ptr
+is
+.Dv NULL ,
+the
+.Fn reallocf
+function behaves identically to
+.Fn malloc
+for the specified size.
+Upon failure, when the requested memory cannot be allocated, the passed pointer
+is freed to ease the problems with traditional coding styles for
+.Fn reallocf
+causing memory leaks in libraries.
+.Sh RETURN VALUES
+The
+.Fn reallocf
+function returns a pointer, possibly identical to
+.Fa ptr ,
+to the allocated memory
+if successful; otherwise a
+.Dv NULL
+pointer is returned, and
+.Va errno
+is set to
+.Er ENOMEM
+if the error was the result of an allocation failure.
+The buffer is deallocated in this case.
+.Sh SEE ALSO
+.Xr brk 2 ,
+.Xr mmap 2 ,
+.Xr alloca 3 ,
+.Xr calloc 3 ,
+.Xr free 3 ,
+.Xr malloc 3 ,
+.Xr posix_memalign 3 ,
+.Xr realloc 3 ,
+.Sh HISTORY
+The
+.Fn reallocf
+function first appeared in
+.Fx 3.0 .
diff --git a/man/setmode.3 b/man/setmode.3
new file mode 100644
index 0000000..ae7c568
--- /dev/null
+++ b/man/setmode.3
@@ -0,0 +1,115 @@
+.\" Copyright (c) 1989, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)setmode.3	8.2 (Berkeley) 4/28/95
+.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
+.\"
+.Dd April 28, 1995
+.Dt SETMODE 3
+.Os
+.Sh NAME
+.Nm getmode ,
+.Nm setmode
+.Nd modify mode bits
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/unistd.h
+.Ft mode_t
+.Fn getmode "const void *set" "mode_t mode"
+.Ft void *
+.Fn setmode "const char *mode_str"
+.Sh DESCRIPTION
+The
+.Fn getmode
+function
+returns a copy of the file permission bits
+.Fa mode
+as altered by the values pointed to by
+.Fa set .
+While only the mode bits are altered, other parts of the file mode
+may be examined.
+.Pp
+The
+.Fn setmode
+function
+takes an absolute (octal) or symbolic value, as described in
+.Xr chmod 1 ,
+as an argument
+and returns a pointer to mode values to be supplied to
+.Fn getmode .
+Because some of the symbolic values are relative to the file
+creation mask,
+.Fn setmode
+may call
+.Xr umask 2 .
+If this occurs, the file creation mask will be restored before
+.Fn setmode
+returns.
+If the calling program changes the value of its file creation mask
+after calling
+.Fn setmode ,
+.Fn setmode
+must be called again if
+.Fn getmode
+is to modify future file modes correctly.
+.Pp
+If the mode passed to
+.Fn setmode
+is invalid or if memory cannot be allocated for the return value,
+.Fn setmode
+returns
+.Dv NULL .
+.Pp
+The value returned from
+.Fn setmode
+is obtained from
+.Fn malloc
+and should be returned to the system with
+.Fn free
+when the program is done with it, generally after a call to
+.Fn getmode .
+.Sh ERRORS
+The
+.Fn setmode
+function
+may fail and set errno for any of the errors specified for the library
+routine
+.Xr malloc 3 .
+.Sh SEE ALSO
+.Xr chmod 1 ,
+.Xr stat 2 ,
+.Xr umask 2 ,
+.Xr malloc 3
+.Sh HISTORY
+The
+.Fn getmode
+and
+.Fn setmode
+functions first appeared in
+.Bx 4.4 .
diff --git a/man/sradixsort.3 b/man/sradixsort.3
new file mode 100644
index 0000000..86a95a3
--- /dev/null
+++ b/man/sradixsort.3
@@ -0,0 +1 @@
+.so man3/radixsort.3
diff --git a/man/strlcat.3 b/man/strlcat.3
new file mode 100644
index 0000000..d968886
--- /dev/null
+++ b/man/strlcat.3
@@ -0,0 +1 @@
+.so man3/strlcpy.3
diff --git a/man/strlcpy.3 b/man/strlcpy.3
new file mode 100644
index 0000000..bf14b4f
--- /dev/null
+++ b/man/strlcpy.3
@@ -0,0 +1,191 @@
+.\" $OpenBSD: strlcpy.3,v 1.18 2005/08/06 03:24:19 jaredy Exp $
+.\"
+.\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller at courtesan.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: May 31 2007 $
+.Dt STRLCPY 3
+.Os
+.Sh NAME
+.Nm strlcpy ,
+.Nm strlcat
+.Nd size-bounded string copying and concatenation
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/string.h
+.Ft size_t
+.Fn strlcpy "char *dst" "const char *src" "size_t size"
+.Ft size_t
+.Fn strlcat "char *dst" "const char *src" "size_t size"
+.Sh DESCRIPTION
+The
+.Fn strlcpy
+and
+.Fn strlcat
+functions copy and concatenate strings respectively.
+They are designed
+to be safer, more consistent, and less error prone replacements for
+.Xr strncpy 3
+and
+.Xr strncat 3 .
+Unlike those functions,
+.Fn strlcpy
+and
+.Fn strlcat
+take the full size of the buffer (not just the length) and guarantee to
+NUL-terminate the result (as long as
+.Fa size
+is larger than 0 or, in the case of
+.Fn strlcat ,
+as long as there is at least one byte free in
+.Fa dst ) .
+Note that a byte for the NUL should be included in
+.Fa size .
+Also note that
+.Fn strlcpy
+and
+.Fn strlcat
+only operate on true
+.Dq C
+strings.
+This means that for
+.Fn strlcpy
+.Fa src
+must be NUL-terminated and for
+.Fn strlcat
+both
+.Fa src
+and
+.Fa dst
+must be NUL-terminated.
+.Pp
+The
+.Fn strlcpy
+function copies up to
+.Fa size
+- 1 characters from the NUL-terminated string
+.Fa src
+to
+.Fa dst ,
+NUL-terminating the result.
+.Pp
+The
+.Fn strlcat
+function appends the NUL-terminated string
+.Fa src
+to the end of
+.Fa dst .
+It will append at most
+.Fa size
+- strlen(dst) - 1 bytes, NUL-terminating the result.
+.Sh RETURN VALUES
+The
+.Fn strlcpy
+and
+.Fn strlcat
+functions return the total length of the string they tried to create.
+For
+.Fn strlcpy
+that means the length of
+.Fa src .
+For
+.Fn strlcat
+that means the initial length of
+.Fa dst
+plus
+the length of
+.Fa src .
+While this may seem somewhat confusing, it was done to make
+truncation detection simple.
+.Pp
+Note, however, that if
+.Fn strlcat
+traverses
+.Fa size
+characters without finding a NUL, the length of the string is considered
+to be
+.Fa size
+and the destination string will not be NUL-terminated (since there was
+no space for the NUL).
+This keeps
+.Fn strlcat
+from running off the end of a string.
+In practice this should not happen (as it means that either
+.Fa size
+is incorrect or that
+.Fa dst
+is not a proper
+.Dq C
+string).
+The check exists to prevent potential security problems in incorrect code.
+.Sh EXAMPLES
+The following code fragment illustrates the simple case:
+.Bd -literal -offset indent
+char *s, *p, buf[BUFSIZ];
+
+\&...
+
+(void)strlcpy(buf, s, sizeof(buf));
+(void)strlcat(buf, p, sizeof(buf));
+.Ed
+.Pp
+To detect truncation, perhaps while building a pathname, something
+like the following might be used:
+.Bd -literal -offset indent
+char *dir, *file, pname[MAXPATHLEN];
+
+\&...
+
+if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
+	goto toolong;
+if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
+	goto toolong;
+.Ed
+.Pp
+Since it is known how many characters were copied the first time, things
+can be sped up a bit by using a copy instead of an append:
+.Bd -literal -offset indent
+char *dir, *file, pname[MAXPATHLEN];
+size_t n;
+
+\&...
+
+n = strlcpy(pname, dir, sizeof(pname));
+if (n >= sizeof(pname))
+	goto toolong;
+if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n)
+	goto toolong;
+.Ed
+.Pp
+However, one may question the validity of such optimizations, as they
+defeat the whole purpose of
+.Fn strlcpy
+and
+.Fn strlcat .
+As a matter of fact, the first version of this manual page got it wrong.
+.Sh SEE ALSO
+.Xr snprintf 3 ,
+.Xr strncat 3 ,
+.Xr strncpy 3
+.Sh HISTORY
+The
+.Fn strlcpy
+and
+.Fn strlcat
+functions first appeared in
+.Ox 2.4 ,
+and made their appearance in
+.Fx 3.3 .
diff --git a/man/strmode.3 b/man/strmode.3
new file mode 100644
index 0000000..70264c0
--- /dev/null
+++ b/man/strmode.3
@@ -0,0 +1,145 @@
+.\" Copyright (c) 1990, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)strmode.3	8.3 (Berkeley) 7/28/94
+.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
+.\"
+.Dd July 28, 1994
+.Dt STRMODE 3
+.Os
+.Sh NAME
+.Nm strmode
+.Nd convert inode status information into a symbolic string
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/string.h
+.Ft void
+.Fn strmode "mode_t mode" "char *bp"
+.Sh DESCRIPTION
+The
+.Fn strmode
+function
+converts a file
+.Fa mode
+(the type and permission information associated with an inode, see
+.Xr stat 2 )
+into a symbolic string which is stored in the location referenced by
+.Fa bp .
+This stored string is eleven characters in length plus a trailing
+.Dv NUL .
+.Pp
+The first character is the inode type, and will be one of the following:
+.Pp
+.Bl -tag -width flag -offset indent -compact
+.It \-
+regular file
+.It b
+block special
+.It c
+character special
+.It d
+directory
+.It l
+symbolic link
+.It p
+fifo
+.It s
+socket
+.It w
+whiteout
+.It ?
+unknown inode type
+.El
+.Pp
+The next nine characters encode three sets of permissions, in three
+characters each.
+The first three characters are the permissions for the owner of the
+file, the second three for the group the file belongs to, and the
+third for the ``other'', or default, set of users.
+.Pp
+Permission checking is done as specifically as possible.
+If read permission is denied to the owner of a file in the first set
+of permissions, the owner of the file will not be able to read the file.
+This is true even if the owner is in the file's group and the group
+permissions allow reading or the ``other'' permissions allow reading.
+.Pp
+If the first character of the three character set is an ``r'', the file is
+readable for that set of users; if a dash ``\-'', it is not readable.
+.Pp
+If the second character of the three character set is a ``w'', the file is
+writable for that set of users; if a dash ``\-'', it is not writable.
+.Pp
+The third character is the first of the following characters that apply:
+.Bl -tag -width xxxx
+.It S
+If the character is part of the owner permissions and the file is not
+executable or the directory is not searchable by the owner, and the
+set-user-id bit is set.
+.It S
+If the character is part of the group permissions and the file is not
+executable or the directory is not searchable by the group, and the
+set-group-id bit is set.
+.It T
+If the character is part of the other permissions and the file is not
+executable or the directory is not searchable by others, and the ``sticky''
+.Pq Dv S_ISVTX
+bit is set.
+.It s
+If the character is part of the owner permissions and the file is
+executable or the directory searchable by the owner, and the set-user-id
+bit is set.
+.It s
+If the character is part of the group permissions and the file is
+executable or the directory searchable by the group, and the set-group-id
+bit is set.
+.It t
+If the character is part of the other permissions and the file is
+executable or the directory searchable by others, and the ``sticky''
+.Pq Dv S_ISVTX
+bit is set.
+.It x
+The file is executable or the directory is searchable.
+.It \-
+None of the above apply.
+.El
+.Pp
+The last character is a plus sign ``+'' if any there are any alternate
+or additional access control methods associated with the inode, otherwise
+it will be a space.
+.Sh SEE ALSO
+.Xr chmod 1 ,
+.Xr find 1 ,
+.Xr stat 2 ,
+.Xr getmode 3 ,
+.Xr setmode 3
+.Sh HISTORY
+The
+.Fn strmode
+function first appeared in
+.Bx 4.4 .
diff --git a/man/strtonum.3 b/man/strtonum.3
new file mode 100644
index 0000000..42674f0
--- /dev/null
+++ b/man/strtonum.3
@@ -0,0 +1,159 @@
+.\" Copyright (c) 2004 Ted Unangst
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\" $OpenBSD: strtonum.3,v 1.12 2005/10/26 11:37:58 jmc Exp $
+.\" $FreeBSD$
+.\"
+.Dd April 29, 2004
+.Dt STRTONUM 3
+.Os
+.Sh NAME
+.Nm strtonum
+.Nd "reliably convert string value to an integer"
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In limits.h
+.In bsd/stdlib.h
+.Ft long long
+.Fo strtonum
+.Fa "const char *nptr"
+.Fa "long long minval"
+.Fa "long long maxval"
+.Fa "const char **errstr"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn strtonum
+function converts the string in
+.Fa nptr
+to a
+.Vt "long long"
+value.
+The
+.Fn strtonum
+function was designed to facilitate safe, robust programming
+and overcome the shortcomings of the
+.Xr atoi 3
+and
+.Xr strtol 3
+family of interfaces.
+.Pp
+The string may begin with an arbitrary amount of whitespace
+(as determined by
+.Xr isspace 3 )
+followed by a single optional
+.Ql +
+or
+.Ql -
+sign.
+.Pp
+The remainder of the string is converted to a
+.Vt "long long"
+value according to base 10.
+.Pp
+The value obtained is then checked against the provided
+.Fa minval
+and
+.Fa maxval
+bounds.
+If
+.Fa errstr
+is non-null,
+.Fn strtonum
+stores an error string in
+.Fa *errstr
+indicating the failure.
+.Sh RETURN VALUES
+The
+.Fn strtonum
+function returns the result of the conversion,
+unless the value would exceed the provided bounds or is invalid.
+On error, 0 is returned,
+.Va errno
+is set, and
+.Fa errstr
+will point to an error message.
+On success,
+.Fa *errstr
+will be set to
+.Dv NULL ;
+this fact can be used to differentiate
+a successful return of 0 from an error.
+.Sh EXAMPLES
+Using
+.Fn strtonum
+correctly is meant to be simpler than the alternative functions.
+.Bd -literal -offset indent
+int iterations;
+const char *errstr;
+
+iterations = strtonum(optarg, 1, 64, &errstr);
+if (errstr)
+	errx(1, "number of iterations is %s: %s", errstr, optarg);
+.Ed
+.Pp
+The above example will guarantee that the value of iterations is between
+1 and 64 (inclusive).
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er ERANGE
+The given string was out of range.
+.It Bq Er EINVAL
+The given string did not consist solely of digit characters.
+.It Bq Er EINVAL
+The supplied
+.Fa minval
+was larger than
+.Fa maxval .
+.El
+.Pp
+If an error occurs,
+.Fa errstr
+will be set to one of the following strings:
+.Pp
+.Bl -tag -width ".Li too large" -compact
+.It Li "too large"
+The result was larger than the provided maximum value.
+.It Li "too small"
+The result was smaller than the provided minimum value.
+.It Li invalid
+The string did not consist solely of digit characters.
+.El
+.Sh SEE ALSO
+.Xr atof 3 ,
+.Xr atoi 3 ,
+.Xr atol 3 ,
+.Xr atoll 3 ,
+.Xr sscanf 3 ,
+.Xr strtod 3 ,
+.Xr strtol 3 ,
+.Xr strtoul 3
+.Sh STANDARDS
+The
+.Fn strtonum
+function is a
+.Bx
+extension.
+The existing alternatives, such as
+.Xr atoi 3
+and
+.Xr strtol 3 ,
+are either impossible or difficult to use safely.
+.Sh HISTORY
+The
+.Fn strtonum
+function first appeared in
+.Ox 3.6 .
diff --git a/man/unvis.3 b/man/unvis.3
new file mode 100644
index 0000000..5e01f88
--- /dev/null
+++ b/man/unvis.3
@@ -0,0 +1,198 @@
+.\"	$OpenBSD: unvis.3,v 1.15 2005/07/22 03:16:58 jaredy Exp $
+.\"
+.\" Copyright (c) 1989, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd $Mdocdate: May 31 2007 $
+.Dt UNVIS 3
+.Os
+.Sh NAME
+.Nm unvis ,
+.Nm strunvis ,
+.Nm strnunvis
+.Nd decode a visual representation of characters
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In bsd/vis.h
+.Ft int
+.Fn unvis "char *cp" "char c" "int *astate" "int flag"
+.Ft int
+.Fn strunvis "char *dst" "char *src"
+.Ft ssize_t
+.Fn strnunvis "char *dst" "char *src" "size_t size"
+.Sh DESCRIPTION
+The
+.Fn unvis ,
+.Fn strunvis
+and
+.Fn strnunvis
+functions are used to decode a visual representation of characters,
+as produced by the
+.Xr vis 3
+function, back into the original form.
+.Fn unvis
+is called with successive characters in
+.Fa c
+until a valid
+sequence is recognized, at which time the decoded character is
+available at the character pointed to by
+.Fa cp .
+.Pp
+.Fn strunvis
+decodes the characters pointed to by
+.Fa src
+into the buffer pointed to by
+.Fa dst .
+.Pp
+.Fn strnunvis
+decodes the characters pointed to by
+.Fa src
+into the buffer pointed to by
+.Fa dst ,
+writing a maximum of
+.Fa size
+bytes.
+The
+.Fn strunvis
+function simply copies
+.Fa src
+to
+.Fa dst ,
+decoding any escape sequences along the way,
+and returns the number of characters placed into
+.Fa dst ,
+or \-1 if an
+invalid escape sequence was detected.
+The size of
+.Fa dst
+should be
+equal to the size of
+.Fa src
+(that is, no expansion takes place during decoding).
+.Fn strunvis
+terminates the destination string with a trailing NUL byte;
+.Fn strnunvis
+does so if
+.Fa size
+is larger than 0.
+.Pp
+The
+.Fn unvis
+function implements a state machine that can be used to decode an arbitrary
+stream of bytes.
+All state associated with the bytes being decoded is stored outside the
+.Fn unvis
+function (that is, a pointer to the state is passed in), so
+calls decoding different streams can be freely intermixed.
+To start decoding a stream of bytes, first initialize an integer
+to zero.
+Call
+.Fn unvis
+with each successive byte, along with a pointer
+to this integer, and a pointer to a destination character.
+.Sh RETURN VALUES
+The
+.Fn unvis
+function has several return codes that must be handled properly.
+They are:
+.Bl -tag -width UNVIS_VALIDPUSH
+.It Li \&0 (zero)
+Another character is necessary; nothing has been recognized yet.
+.It Dv UNVIS_VALID
+A valid character has been recognized and is available at the location
+pointed to by
+.Fa cp .
+.It Dv UNVIS_VALIDPUSH
+A valid character has been recognized and is available at the location
+pointed to by
+.Fa cp ;
+however, the character currently passed in should be passed in again.
+.It Dv UNVIS_NOCHAR
+A valid sequence was detected, but no character was produced.
+This return code is necessary to indicate a logical break between characters.
+.It Dv UNVIS_SYNBAD
+An invalid escape sequence was detected, or the decoder is in an
+unknown state.
+The decoder is placed into the starting state.
+.El
+.Pp
+When all bytes in the stream have been processed, call
+.Fn unvis
+one more time with
+.Fa flag
+set to
+.Dv UNVIS_END
+to extract any remaining character (the character passed in is ignored).
+.Pp
+The
+.Fn strunvis
+function returns the number of bytes written (not counting
+the trailing NUL byte) or \-1 if an error occurred.
+.Pp
+The
+.Fn strnunvis
+function returns the number of bytes (not counting the trailing NUL byte)
+that would be needed to fully convert the input string, or \-1 if an
+error occurred.
+.Sh EXAMPLES
+The following code fragment illustrates a proper use of
+.Fn unvis .
+.Bd -literal -offset indent
+int state = 0;
+char out;
+
+while ((ch = getchar()) != EOF) {
+again:
+	switch(unvis(&out, ch, &state, 0)) {
+	case 0:
+	case UNVIS_NOCHAR:
+		break;
+	case UNVIS_VALID:
+		(void) putchar(out);
+		break;
+	case UNVIS_VALIDPUSH:
+		(void) putchar(out);
+		goto again;
+	case UNVIS_SYNBAD:
+		(void)fprintf(stderr, "bad sequence!\en");
+		exit(1);
+	}
+}
+if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID)
+	(void) putchar(out);
+.Ed
+.Sh SEE ALSO
+.Xr unvis 1 ,
+.Xr vis 1 ,
+.Xr vis 3
+.Sh HISTORY
+The
+.Fn unvis
+function first appeared in
+.Bx 4.4 .
diff --git a/man/vis.3 b/man/vis.3
new file mode 100644
index 0000000..65548f0
--- /dev/null
+++ b/man/vis.3
@@ -0,0 +1,321 @@
+.\"	$OpenBSD: vis.3,v 1.23 2005/08/28 19:51:27 millert Exp $
+.\"
+.\" Copyright (c) 1989, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd $Mdocdate: May 31 2007 $
+.Dt VIS 3
+.Os
+.Sh NAME
+.Nm vis ,
+.Nm strvis ,
+.Nm strnvis ,
+.Nm strvisx
+.Nd visually encode characters
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In stdlib.h
+.In bsd/vis.h
+.Ft char *
+.Fn vis "char *dst" "int c" "int flag" "int nextc"
+.Ft int
+.Fn strvis "char *dst" "const char *src" "int flag"
+.Ft int
+.Fn strnvis "char *dst" "const char *src" "size_t size" "int flag"
+.Ft int
+.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
+.Sh DESCRIPTION
+The
+.Fn vis
+function copies into
+.Fa dst
+a string which represents the character
+.Fa c .
+If
+.Fa c
+needs no encoding, it is copied in unaltered.
+The string is NUL terminated and a pointer to the end of the string is
+returned.
+The maximum length of any encoding is four
+characters (not including the trailing NUL);
+thus, when
+encoding a set of characters into a buffer, the size of the buffer should
+be four times the number of characters encoded, plus one for the trailing
+NUL.
+The
+.Fa flag
+parameter is used for altering the default range of
+characters considered for encoding and for altering the visual
+representation.
+The additional character,
+.Fa nextc ,
+is only used when selecting the
+.Dv VIS_CSTYLE
+encoding format (explained below).
+.Pp
+The
+.Fn strvis ,
+.Fn strnvis
+and
+.Fn strvisx
+functions copy into
+.Fa dst
+a visual representation of
+the string
+.Fa src .
+The
+.Fn strvis
+function encodes characters from
+.Fa src
+up to the first NUL.
+The
+.Fn strnvis
+function encodes characters from
+.Fa src
+up to the first NUL or the end of
+.Fa dst ,
+as indicated by
+.Fa size .
+The
+.Fn strvisx
+function encodes exactly
+.Fa len
+characters from
+.Fa src
+(this
+is useful for encoding a block of data that may contain NULs).
+All three forms NUL terminate
+.Fa dst ,
+except for
+.Fn strnvis
+when
+.Fa size
+is zero, in which case
+.Fa dst
+is not touched.
+For
+.Fn strvis
+and
+.Fn strvisx ,
+the size of
+.Fa dst
+must be four times the number
+of characters encoded from
+.Fa src
+(plus one for the NUL).
+.Fn strvis
+and
+.Fn strvisx
+return the number of characters in
+.Fa dst
+(not including the trailing NUL).
+.Fn strnvis
+returns the length that
+.Fa dst
+would become if it were of unlimited size (similar to
+.Xr snprintf 3
+or
+.Xr strlcpy 3 ) .
+This can be used to detect truncation but it also means that
+the return value of
+.Fn strnvis
+must not be used without checking it against
+.Fa size .
+.Pp
+The encoding is a unique, invertible representation composed entirely of
+graphic characters; it can be decoded back into the original form using
+the
+.Xr unvis 3
+or
+.Xr strunvis 3
+functions.
+.Pp
+There are two parameters that can be controlled: the range of
+characters that are encoded, and the type
+of representation used.
+By default, all non-graphic characters
+except space, tab, and newline are encoded
+(see
+.Xr isgraph 3 ) .
+The following flags
+alter this:
+.Bl -tag -width VIS_WHITEX
+.It Dv VIS_GLOB
+Also encode magic characters recognized by
+.Xr glob 3
+.Pf ( Ql * ,
+.Ql \&? ,
+.Ql \&[ )
+and
+.Ql # .
+.It Dv VIS_SP
+Also encode space.
+.It Dv VIS_TAB
+Also encode tab.
+.It Dv VIS_NL
+Also encode newline.
+.It Dv VIS_WHITE
+Synonym for
+.Dv VIS_SP
+\&|
+.Dv VIS_TAB
+\&|
+.Dv VIS_NL .
+.It Dv VIS_SAFE
+Only encode
+.Dq unsafe
+characters.
+These are control characters which may cause common terminals to perform
+unexpected functions.
+Currently this form allows space,
+tab, newline, backspace, bell, and return -- in addition
+to all graphic characters -- unencoded.
+.El
+.Pp
+There are three forms of encoding.
+All forms use the backslash
+.Ql \e
+character to introduce a special
+sequence; two backslashes are used to represent a real backslash.
+These are the visual formats:
+.Bl -tag -width VIS_CSTYLE
+.It (default)
+Use an
+.Ql M
+to represent meta characters (characters with the 8th
+bit set), and use a caret
+.Ql ^
+to represent control characters (see
+.Xr iscntrl 3 ) .
+The following formats are used:
+.Bl -tag -width xxxxx
+.It Dv \e^C
+Represents the control character
+.Ql C .
+Spans characters
+.Ql \e000
+through
+.Ql \e037 ,
+and
+.Ql \e177
+(as
+.Ql \e^? ) .
+.It Dv \eM-C
+Represents character
+.Ql C
+with the 8th bit set.
+Spans characters
+.Ql \e241
+through
+.Ql \e376 .
+.It Dv \eM^C
+Represents control character
+.Ql C
+with the 8th bit set.
+Spans characters
+.Ql \e200
+through
+.Ql \e237 ,
+and
+.Ql \e377
+(as
+.Ql \eM^? ) .
+.It Dv \e040
+Represents
+.Tn ASCII
+space.
+.It Dv \e240
+Represents Meta-space.
+.El
+.Pp
+.It Dv VIS_CSTYLE
+Use C-style backslash sequences to represent standard non-printable
+characters.
+The following sequences are used to represent the indicated characters:
+.Bd -unfilled -offset indent
+.Li \ea Tn  - BEL No (007)
+.Li \eb Tn  - BS No (010)
+.Li \ef Tn  - NP No (014)
+.Li \en Tn  - NL No (012)
+.Li \er Tn  - CR No (015)
+.Li \es Tn  - SP No (040)
+.Li \et Tn  - HT No (011)
+.Li \ev Tn  - VT No (013)
+.Li \e0 Tn  - NUL No (000)
+.Ed
+.Pp
+When using this format, the
+.Fa nextc
+parameter is looked at to determine
+if a NUL character can be encoded as
+.Ql \e0
+instead of
+.Ql \e000 .
+If
+.Fa nextc
+is an octal digit, the latter representation is used to
+avoid ambiguity.
+.It Dv VIS_OCTAL
+Use a three digit octal sequence.
+The form is
+.Ql \eddd
+where
+.Ar d
+represents an octal digit.
+.El
+.Pp
+There is one additional flag,
+.Dv VIS_NOSLASH ,
+which inhibits the
+doubling of backslashes and the backslash before the default
+format (that is, control characters are represented by
+.Ql ^C
+and
+meta characters as
+.Ql M-C ) .
+With this flag set, the encoding is
+ambiguous and non-invertible.
+.Sh SEE ALSO
+.Xr unvis 1 ,
+.Xr vis 1 ,
+.Xr snprintf 3 ,
+.Xr strlcpy 3 ,
+.Xr unvis 3
+.Sh HISTORY
+The
+.Fn vis ,
+.Fn strvis
+and
+.Fn strvisx
+functions first appeared in
+.Bx 4.4 .
+The
+.Fn strnvis
+function first appeared in
+.Ox 2.9 .
diff --git a/src/.gitignore b/src/.gitignore
deleted file mode 100644
index ed4f453..0000000
--- a/src/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-md5.3
-md5.3bsd
diff --git a/src/arc4random.3 b/src/arc4random.3
deleted file mode 100644
index eda74af..0000000
--- a/src/arc4random.3
+++ /dev/null
@@ -1,128 +0,0 @@
-.\" $OpenBSD: arc4random.3,v 1.2 1997/04/27 22:40:25 angelos Exp $
-.\" Copyright 1997 Niels Provos <provos at physnet.uni-hamburg.de>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"      This product includes software developed by Niels Provos.
-.\" 4. The name of the author may not be used to endorse or promote products
-.\"    derived from this software without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-.\"
-.\" Manual page, using -mandoc macros
-.\" $FreeBSD$
-.\"
-.Dd April 15, 1997
-.Dt ARC4RANDOM 3
-.Os
-.Sh NAME
-.Nm arc4random ,
-.Nm arc4random_buf ,
-.Nm arc4random_uniform ,
-.Nm arc4random_stir ,
-.Nm arc4random_addrandom
-.Nd arc4 random number generator
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/stdlib.h
-.Ft u_int32_t
-.Fn arc4random "void"
-.Ft void
-.Fn arc4random_buf "void *buf" "size_t nbytes"
-.Ft u_int32_t
-.Fn arc4random_uniform "u_int32_t upper_bound"
-.Ft void
-.Fn arc4random_stir "void"
-.Ft void
-.Fn arc4random_addrandom "unsigned char *dat" "int datlen"
-.Sh DESCRIPTION
-The
-.Fn arc4random
-function uses the key stream generator employed by the
-arc4 cipher, which uses 8*8 8 bit S-Boxes.
-The S-Boxes
-can be in about
-.if t 2\u\s71700\s10\d
-.if n (2**1700)
-states.
-The
-.Fn arc4random
-function returns pseudo-random numbers in the range of 0 to
-.if t 2\u\s731\s10\d\(mi1,
-.if n (2**32)\(mi1,
-and therefore has twice the range of
-.Xr rand 3
-and
-.Xr random 3 .
-.Pp
-.Fn arc4random_buf
-function fills the region
-.Fa buf
-of length
-.Fa nbytes
-with ARC4-derived random data.
-.Pp
-.Fn arc4random_uniform
-will return a uniformly distributed random number less than
-.Fa upper_bound .
-.Fn arc4random_uniform
-is recommended over constructions like
-.Dq Li arc4random() % upper_bound
-as it avoids "modulo bias" when the upper bound is not a power of two.
-.Pp
-The
-.Fn arc4random_stir
-function reads data from
-.Pa /dev/urandom
-and uses it to permute the S-Boxes via
-.Fn arc4random_addrandom .
-.Pp
-There is no need to call
-.Fn arc4random_stir
-before using
-.Fn arc4random
-functions family, since
-they automatically initialize themselves.
-.Sh EXAMPLES
-The following produces a drop-in replacement for the traditional
-.Fn rand
-and
-.Fn random
-functions using
-.Fn arc4random :
-.Pp
-.Dl "#define foo4random() (arc4random() % ((unsigned)RAND_MAX + 1))"
-.Sh SEE ALSO
-.Xr rand 3 ,
-.Xr random 3 ,
-.Xr srandomdev 3
-.Sh HISTORY
-.Pa RC4
-has been designed by RSA Data Security, Inc.
-It was posted anonymously
-to the USENET and was confirmed to be equivalent by several sources who
-had access to the original cipher.
-Since
-.Pa RC4
-used to be a trade secret, the cipher is now referred to as
-.Pa ARC4 .
diff --git a/src/arc4random_addrandom.3 b/src/arc4random_addrandom.3
deleted file mode 100644
index 74a34ce..0000000
--- a/src/arc4random_addrandom.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/arc4random.3
diff --git a/src/arc4random_buf.3 b/src/arc4random_buf.3
deleted file mode 100644
index 74a34ce..0000000
--- a/src/arc4random_buf.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/arc4random.3
diff --git a/src/arc4random_stir.3 b/src/arc4random_stir.3
deleted file mode 100644
index 74a34ce..0000000
--- a/src/arc4random_stir.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/arc4random.3
diff --git a/src/arc4random_uniform.3 b/src/arc4random_uniform.3
deleted file mode 100644
index 74a34ce..0000000
--- a/src/arc4random_uniform.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/arc4random.3
diff --git a/src/dehumanize_number.3 b/src/dehumanize_number.3
deleted file mode 100644
index 7f5dcf3..0000000
--- a/src/dehumanize_number.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/humanize_number.3
diff --git a/src/fgetln.3 b/src/fgetln.3
deleted file mode 100644
index 7dd3fc8..0000000
--- a/src/fgetln.3
+++ /dev/null
@@ -1,125 +0,0 @@
-.\" Copyright (c) 1990, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)fgetln.3	8.3 (Berkeley) 4/19/94
-.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
-.\"
-.Dd April 19, 1994
-.Dt FGETLN 3
-.Os
-.Sh NAME
-.Nm fgetln
-.Nd get a line from a stream
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/stdio.h
-.Ft char *
-.Fn fgetln "FILE *stream" "size_t *len"
-.Sh DESCRIPTION
-The
-.Fn fgetln
-function
-returns a pointer to the next line from the stream referenced by
-.Fa stream .
-This line is
-.Em not
-a C string as it does not end with a terminating
-.Dv NUL
-character.
-The length of the line, including the final newline,
-is stored in the memory location to which
-.Fa len
-points and is guaranteed to be greater than 0 upon successful completion.
-(Note, however, that if the line is the last
-in a file that does not end in a newline,
-the returned text will not contain a newline.)
-.Sh RETURN VALUES
-Upon successful completion a pointer is returned;
-this pointer becomes invalid after the next
-.Tn I/O
-operation on
-.Fa stream
-(whether successful or not)
-or as soon as the stream is closed.
-Otherwise,
-.Dv NULL
-is returned.
-The
-.Fn fgetln
-function
-does not distinguish between end-of-file and error; the routines
-.Xr feof 3
-and
-.Xr ferror 3
-must be used
-to determine which occurred.
-If an error occurs, the global variable
-.Va errno
-is set to indicate the error.
-The end-of-file condition is remembered, even on a terminal, and all
-subsequent attempts to read will return
-.Dv NULL
-until the condition is
-cleared with
-.Xr clearerr 3 .
-.Pp
-The text to which the returned pointer points may be modified,
-provided that no changes are made beyond the returned size.
-These changes are lost as soon as the pointer becomes invalid.
-.Sh ERRORS
-.Bl -tag -width Er
-.It Bq Er EBADF
-The argument
-.Fa stream
-is not a stream open for reading.
-.El
-.Pp
-The
-.Fn fgetln
-function
-may also fail and set
-.Va errno
-for any of the errors specified for the routines
-.Xr fflush 3 ,
-.Xr malloc 3 ,
-.Xr read 2 ,
-.Xr stat 2 ,
-or
-.Xr realloc 3 .
-.Sh SEE ALSO
-.Xr ferror 3 ,
-.Xr fgets 3 ,
-.Xr fgetwln 3 ,
-.Xr fopen 3 ,
-.Xr putc 3
-.Sh HISTORY
-The
-.Fn fgetln
-function first appeared in
-.Bx 4.4 .
diff --git a/src/flopen.3 b/src/flopen.3
deleted file mode 100644
index 8f81211..0000000
--- a/src/flopen.3
+++ /dev/null
@@ -1,102 +0,0 @@
-.\"-
-.\" Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd June 6, 2009
-.Dt FLOPEN 3
-.Os
-.Sh NAME
-.Nm flopen
-.Nd "Reliably open and lock a file"
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In sys/fcntl.h
-.In bsd/libutil.h
-.Ft int
-.Fn flopen "const char *path" "int flags"
-.Ft int
-.Fn flopen "const char *path" "int flags" "mode_t mode"
-.Sh DESCRIPTION
-The
-.Fn flopen
-function opens or creates a file and acquires an exclusive lock on it.
-It is essentially equivalent with calling
-.Fn open
-with the same parameters followed by
-.Fn flock
-with an
-.Va operation
-argument of
-.Dv LOCK_EX ,
-except that
-.Fn flopen
-will attempt to detect and handle races that may occur between opening
-/ creating the file and locking it.
-Thus, it is well suited for opening lock files, PID files, spool
-files, mailboxes and other kinds of files which are used for
-synchronization between processes.
-.Pp
-If
-.Va flags
-includes
-.Dv O_NONBLOCK
-and the file is already locked,
-.Fn flopen
-will fail and set
-.Va errno
-to
-.Dv EWOULDBLOCK .
-.Pp
-As with
-.Fn open ,
-the additional
-.Va mode
-argument is required if
-.Va flags
-includes
-.Dv O_CREAT .
-.Sh RETURN VALUES
-If successful,
-.Fn flopen
-returns a valid file descriptor.
-Otherwise, it returns -1, and sets
-.Va errno
-as described in
-.Xr flock 2
-and
-.Xr open 2 .
-.Sh SEE ALSO
-.Xr errno 2 ,
-.Xr flock 2 ,
-.Xr open 2
-.Sh AUTHORS
-.An -nosplit
-The
-.Nm
-function and this manual page were written by
-.An Dag-Erling Sm\(/orgrav Aq des at FreeBSD.org .
diff --git a/src/fmtcheck.3 b/src/fmtcheck.3
deleted file mode 100644
index 7bf5d39..0000000
--- a/src/fmtcheck.3
+++ /dev/null
@@ -1,111 +0,0 @@
-.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This file was contributed to The NetBSD Foundation by Allen Briggs.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-.\" POSSIBILITY OF SUCH DAMAGE.
-.\"
-.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/fmtcheck.3,v 1.9 2004/07/02 23:52:10 ru Exp $
-.Dd October 16, 2002
-.Os
-.Dt FMTCHECK 3
-.Sh NAME
-.Nm fmtcheck
-.Nd sanitizes user-supplied
-.Xr printf 3 Ns -style
-format string
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/stdio.h
-.Ft const char *
-.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
-.Sh DESCRIPTION
-The
-.Fn fmtcheck
-scans
-.Fa fmt_suspect
-and
-.Fa fmt_default
-to determine if
-.Fa fmt_suspect
-will consume the same argument types as
-.Fa fmt_default
-and to ensure that
-.Fa fmt_suspect
-is a valid format string.
-.Pp
-The
-.Xr printf 3
-family of functions cannot verify the types of arguments that they are
-passed at run-time.
-In some cases, like
-.Xr catgets 3 ,
-it is useful or necessary to use a user-supplied format string with no
-guarantee that the format string matches the specified arguments.
-.Pp
-The
-.Fn fmtcheck
-was designed to be used in these cases, as in:
-.Bd -literal -offset indent
-printf(fmtcheck(user_format, standard_format), arg1, arg2);
-.Ed
-.Pp
-In the check, field widths, fillers, precisions, etc.\& are ignored (unless
-the field width or precision is an asterisk
-.Ql *
-instead of a digit string).
-Also, any text other than the format specifiers
-is completely ignored.
-.Sh RETURN VALUES
-If
-.Fa fmt_suspect
-is a valid format and consumes the same argument types as
-.Fa fmt_default ,
-then the
-.Fn fmtcheck
-will return
-.Fa fmt_suspect .
-Otherwise, it will return
-.Fa fmt_default .
-.Sh SECURITY CONSIDERATIONS
-Note that the formats may be quite different as long as they accept the
-same arguments.
-For example,
-.Qq Li "%p %o %30s %#llx %-10.*e %n"
-is compatible with
-.Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" .
-However,
-.Qq Li %o
-is not equivalent to
-.Qq Li %lx
-because
-the first requires an integer and the second requires a long.
-.Sh SEE ALSO
-.Xr printf 3
-.Sh BUGS
-The
-.Fn fmtcheck
-function does not understand all of the conversions that
-.Xr printf 3
-does.
diff --git a/src/getmode.3 b/src/getmode.3
deleted file mode 100644
index 63315e7..0000000
--- a/src/getmode.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/setmode.3
diff --git a/src/getpeereid.3 b/src/getpeereid.3
deleted file mode 100644
index 84c776e..0000000
--- a/src/getpeereid.3
+++ /dev/null
@@ -1,138 +0,0 @@
-.\"
-.\" Copyright (c) 2001 Dima Dorfman.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd July 15, 2001
-.Dt GETPEEREID 3
-.Os
-.Sh NAME
-.Nm getpeereid
-.Nd get the effective credentials of a UNIX-domain peer
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In sys/types.h
-.In bsd/unistd.h
-.Ft int
-.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid"
-.Sh DESCRIPTION
-The
-.Fn getpeereid
-function returns the effective user and group IDs of the
-peer connected to a
-.Ux Ns -domain
-socket.
-The argument
-.Fa s
-must be a
-.Ux Ns -domain
-socket
-.Pq Xr unix 4
-of type
-.Dv SOCK_STREAM
-on which either
-.Xr connect 2
-or
-.Xr listen 2
-have been called.
-The effective used ID is placed in
-.Fa euid ,
-and the effective group ID in
-.Fa egid .
-.Pp
-The credentials returned to the
-.Xr listen 2
-caller are those of its peer at the time it called
-.Xr connect 2 ;
-the credentials returned to the
-.Xr connect 2
-caller are those of its peer at the time it called
-.Xr listen 2 .
-This mechanism is reliable; there is no way for either side to influence
-the credentials returned to its peer except by calling the appropriate
-system call (i.e., either
-.Xr connect 2
-or
-.Xr listen 2 )
-under different effective credentials.
-.Pp
-One common use of this routine is for a
-.Ux Ns -domain
-server
-to verify the credentials of its client.
-Likewise, the client can verify the credentials of the server.
-.Sh IMPLEMENTATION NOTES
-On
-.Fx ,
-.Fn getpeereid
-is implemented in terms of the
-.Dv LOCAL_PEERCRED
-.Xr unix 4
-socket option.
-.Sh RETURN VALUES
-.Rv -std getpeereid
-.Sh ERRORS
-The
-.Fn getpeereid
-function
-fails if:
-.Bl -tag -width Er
-.It Bq Er EBADF
-The argument
-.Fa s
-is not a valid descriptor.
-.It Bq Er ENOTSOCK
-The argument
-.Fa s
-is a file, not a socket.
-.It Bq Er ENOTCONN
-The argument
-.Fa s
-does not refer to a socket on which
-.Xr connect 2
-or
-.Xr listen 2
-have been called.
-.It Bq Er EINVAL
-The argument
-.Fa s
-does not refer to a socket of type
-.Dv SOCK_STREAM ,
-or the kernel returned invalid data.
-.El
-.Sh SEE ALSO
-.Xr connect 2 ,
-.Xr getpeername 2 ,
-.Xr getsockname 2 ,
-.Xr getsockopt 2 ,
-.Xr listen 2 ,
-.Xr unix 4
-.Sh HISTORY
-The
-.Fn getpeereid
-function appeared in
-.Fx 4.6 .
diff --git a/src/heapsort.3 b/src/heapsort.3
deleted file mode 100644
index 4261c84..0000000
--- a/src/heapsort.3
+++ /dev/null
@@ -1,208 +0,0 @@
-.\" Copyright (c) 1990, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the American National Standards Committee X3, on Information
-.\" Processing Systems.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd September 30, 2003
-.Dt QSORT 3
-.Os
-.Sh NAME
-.Nm heapsort , mergesort
-.Nd sort functions
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/stdlib.h
-.Ft int
-.Fo heapsort
-.Fa "void *base"
-.Fa "size_t nmemb"
-.Fa "size_t size"
-.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
-.Fc
-.Ft int
-.Fo mergesort
-.Fa "void *base"
-.Fa "size_t nmemb"
-.Fa "size_t size"
-.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
-.Fc
-.Sh DESCRIPTION
-The
-.Fn heapsort
-function is a modified selection sort.
-The
-.Fn mergesort
-function is a modified merge sort with exponential search
-intended for sorting data with pre-existing order.
-.Pp
-The
-.Fn heapsort
-function sorts an array of
-.Fa nmemb
-objects, the initial member of which is pointed to by
-.Fa base .
-The size of each object is specified by
-.Fa size .
-The
-.Fn mergesort
-function
-behaves similarly, but
-.Em requires
-that
-.Fa size
-be greater than
-.Dq "sizeof(void *) / 2" .
-.Pp
-The contents of the array
-.Fa base
-are sorted in ascending order according to
-a comparison function pointed to by
-.Fa compar ,
-which requires two arguments pointing to the objects being
-compared.
-.Pp
-The comparison function must return an integer less than, equal to, or
-greater than zero if the first argument is considered to be respectively
-less than, equal to, or greater than the second.
-.Pp
-The algorithm implemented by
-.Fn heapsort
-is
-.Em not
-stable, that is, if two members compare as equal, their order in
-the sorted array is undefined.
-The
-.Fn mergesort
-algorithm is stable.
-.Pp
-The
-.Fn heapsort
-function is an implementation of
-.An "J.W.J. William" Ns 's
-.Dq heapsort
-algorithm,
-a variant of selection sorting; in particular, see
-.An "D.E. Knuth" Ns 's
-.%T "Algorithm H" .
-.Sy Heapsort
-takes O N lg N worst-case time.
-Its
-.Em only
-advantage over
-.Fn qsort
-is that it uses almost no additional memory; while
-.Fn qsort
-does not allocate memory, it is implemented using recursion.
-.Pp
-The function
-.Fn mergesort
-requires additional memory of size
-.Fa nmemb *
-.Fa size
-bytes; it should be used only when space is not at a premium.
-The
-.Fn mergesort
-function
-is optimized for data with pre-existing order; its worst case
-time is O N lg N; its best case is O N.
-.Pp
-Normally,
-.Fn qsort
-is faster than
-.Fn mergesort
-is faster than
-.Fn heapsort .
-Memory availability and pre-existing order in the data can make this
-untrue.
-.Sh RETURN VALUES
-.Rv -std heapsort mergesort
-.Sh ERRORS
-The
-.Fn heapsort
-and
-.Fn mergesort
-functions succeed unless:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Fa size
-argument is zero, or,
-the
-.Fa size
-argument to
-.Fn mergesort
-is less than
-.Dq "sizeof(void *) / 2" .
-.It Bq Er ENOMEM
-The
-.Fn heapsort
-or
-.Fn mergesort
-functions
-were unable to allocate memory.
-.El
-.Sh SEE ALSO
-.Xr sort 1 ,
-.Xr radixsort 3
-.Rs
-.%A Williams, J.W.J
-.%D 1964
-.%T "Heapsort"
-.%J "Communications of the ACM"
-.%V 7:1
-.%P pp. 347-348
-.Re
-.Rs
-.%A Knuth, D.E.
-.%D 1968
-.%B "The Art of Computer Programming"
-.%V Vol. 3
-.%T "Sorting and Searching"
-.%P pp. 114-123, 145-149
-.Re
-.Rs
-.%A McIlroy, P.M.
-.%T "Optimistic Sorting and Information Theoretic Complexity"
-.%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms"
-.%V January 1992
-.Re
-.Rs
-.%A Bentley, J.L.
-.%A McIlroy, M.D.
-.%T "Engineering a Sort Function"
-.%J "Software--Practice and Experience"
-.%V Vol. 23(11)
-.%P pp. 1249-1265
-.%D November\ 1993
-.Re
diff --git a/src/humanize_number.3 b/src/humanize_number.3
deleted file mode 100644
index e0ffdf0..0000000
--- a/src/humanize_number.3
+++ /dev/null
@@ -1,171 +0,0 @@
-.\"	$NetBSD: humanize_number.3,v 1.8 2008/04/30 13:10:50 martin Exp $
-.\"
-.\" Copyright (c) 1999, 2002, 2008 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to The NetBSD Foundation
-.\" by Luke Mewburn and by Tomas Svensson.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-.\" POSSIBILITY OF SUCH DAMAGE.
-.\"
-.Dd February 9, 2008
-.Dt HUMANIZE_NUMBER 3
-.Os
-.Sh NAME
-.Nm dehumanize_number ,
-.Nm humanize_number
-.Nd format a number into a human readable form and viceversa
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/stdlib.h
-.Ft int
-.Fn dehumanize_number "const char *str" "int64_t *result"
-.Ft int
-.Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags"
-.Sh DESCRIPTION
-The
-.Fn humanize_number
-function formats the signed 64 bit quantity given in
-.Fa number
-into
-.Fa buffer .
-A space and then
-.Fa suffix
-is appended to the end.
-.Fa buffer
-must be at least
-.Fa len
-bytes long.
-.Pp
-If the formatted number (including
-.Fa suffix )
-would be too long to fit into
-.Fa buffer ,
-then divide
-.Fa number
-by 1024 until it will.
-In this case, prefix
-.Fa suffix
-with the appropriate SI designator.
-.Pp
-The prefixes are:
-.Bl -column "Prefix" "Description" "Multiplier" -offset indent
-.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
-.It k	kilo	1024
-.It M	mega	1048576
-.It G	giga	1073741824
-.It T	tera	1099511627776
-.It P	peta	1125899906842624
-.It E	exa	1152921504606846976
-.El
-.Pp
-.Fa len
-must be at least 4 plus the length of
-.Fa suffix ,
-in order to ensure a useful result is generated into
-.Fa buffer .
-To use a specific prefix, specify this as
-.Fa scale
-(Multiplier = 1024 ^ scale).
-This can not be combined with any of the
-.Fa scale
-flags below.
-.Pp
-The following flags may be passed in
-.Pa scale :
-.Bl -tag -width Dv -offset indent
-.It Dv HN_AUTOSCALE
-Format the buffer using the lowest multiplier possible.
-.It Dv HN_GETSCALE
-Return the prefix index number (the number of times
-.Fa number
-must be divided to fit) instead of formatting it to the buffer.
-.El
-.Pp
-The following flags may be passed in
-.Pa flags :
-.Bl -tag -width Dv -offset indent
-.It Dv HN_DECIMAL
-If the final result is less than 10, display it using one digit.
-.It Dv HN_NOSPACE
-Do not put a space between
-.Fa number
-and the prefix.
-.It Dv HN_B
-Use 'B' (bytes) as prefix if the original result does not have a prefix.
-.It Dv HN_DIVISOR_1000
-Divide
-.Fa number
-with 1000 instead of 1024.
-.El
-.Pp
-The
-.Fn dehumanize_number
-function parses the string representing an integral value given in
-.Fa str
-and stores the numerical value in the integer pointed to by
-.Fa result .
-The provided string may hold one of the suffixes, which will be interpreted
-and used to scale up its accompanying numerical value.
-.Sh RETURN VALUES
-.Fn humanize_number
-returns the number of characters stored in
-.Fa buffer
-(excluding the terminating NUL) upon success, or \-1 upon failure.
-If
-.Dv HN_GETSCALE
-is specified, the prefix index number will be returned instead.
-.Pp
-.Fn dehumanize_number
-returns 0 if the string was parsed correctly.
-A \-1 is returned to indicate failure and an error code is stored in
-.Va errno .
-.Sh ERRORS
-.Fn dehumanize_number
-will fail and no number will be stored in
-.Fa result
-if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The string in
-.Fa str
-was empty or carried an unknown suffix.
-.It Bq Er ERANGE
-The string in
-.Fa str
-represented a number that does not fit in
-.Fa result .
-.El
-.Sh SEE ALSO
-.Xr humanize_number 9
-.Sh HISTORY
-.Fn humanize_number
-first appeared in
-.Nx 2.0 .
-.Pp
-.Fn dehumanize_number
-first appeared in
-.\" FIXME: This should be in groff, but for now it avoids the warning.
-.ds operating-system-NetBSD-5.0 5.0
-.Nx 5.0 .
diff --git a/src/mdX.3 b/src/mdX.3
deleted file mode 100644
index 41bf329..0000000
--- a/src/mdX.3
+++ /dev/null
@@ -1,226 +0,0 @@
-.\"
-.\" ----------------------------------------------------------------------------
-.\" "THE BEER-WARE LICENSE" (Revision 42):
-.\" <phk at login.dkuug.dk> wrote this file.  As long as you retain this notice you
-.\" can do whatever you want with this stuff. If we meet some day, and you think
-.\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
-.\" ----------------------------------------------------------------------------
-.\"
-.\" 	$MirOS: src/lib/libc/hash/mdX.3,v 1.4 2007/05/07 16:15:56 tg Exp $
-.\" 	$OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $
-.\"
-.Dd April 29, 2004
-.Dt MDX 3
-.Os
-.Sh NAME
-.Nm MDXInit ,
-.Nm MDXUpdate ,
-.Nm MDXPad ,
-.Nm MDXFinal ,
-.Nm MDXTransform ,
-.Nm MDXEnd ,
-.Nm MDXFile ,
-.Nm MDXFileChunk ,
-.Nm MDXData
-.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.Fd #include <sys/types.h>
-.Fd #include <bsd/mdX.h>
-.Ft void
-.Fn MDXInit "MDX_CTX *context"
-.Ft void
-.Fn MDXUpdate "MDX_CTX *context" "const u_int8_t *data" "size_t len"
-.Ft void
-.Fn MDXPad "MDX_CTX *context"
-.Ft void
-.Fn MDXFinal "u_int8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context"
-.Ft void
-.Fn MDXTransform "u_int32_t state[4]" "u_int8_t block[MDX_BLOCK_LENGTH]"
-.Ft "char *"
-.Fn MDXEnd "MDX_CTX *context" "char *buf"
-.Ft "char *"
-.Fn MDXFile "const char *filename" "char *buf"
-.Ft "char *"
-.Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
-.Ft "char *"
-.Fn MDXData "const u_int8_t *data" "size_t len" "char *buf"
-.Sh DESCRIPTION
-The MDX functions calculate a 128-bit cryptographic checksum (digest)
-for any number of input bytes.
-A cryptographic checksum is a one-way
-hash-function, that is, you cannot find (except by exhaustive search)
-the input corresponding to a particular output.
-This net result is a
-.Dq fingerprint
-of the input-data, which doesn't disclose the actual input.
-.Pp
-MD4 has been broken; it should only be used where necessary for
-backward compatibility.
-MD5 has not yet (1999-02-11) been broken, but recent attacks have cast
-some doubt on its security properties.
-The attacks on both MD4 and MD5
-are both in the nature of finding
-.Dq collisions
-\- that is, multiple
-inputs which hash to the same value; it is still unlikely for an attacker
-to be able to determine the exact original input given a hash value.
-.Pp
-The
-.Fn MDXInit ,
-.Fn MDXUpdate ,
-and
-.Fn MDXFinal
-functions are the core functions.
-Allocate an MDX_CTX, initialize it with
-.Fn MDXInit ,
-run over the data with
-.Fn MDXUpdate ,
-and finally extract the result using
-.Fn MDXFinal .
-.Pp
-The
-.Fn MDXPad
-function can be used to apply padding to the message digest as in
-.Fn MDXFinal ,
-but the current context can still be used with
-.Fn MDXUpdate .
-.Pp
-The
-.Fn MDXTransform
-function is used by
-.Fn MDXUpdate
-to hash 512-bit blocks and forms the core of the algorithm.
-Most programs should use the interface provided by
-.Fn MDXInit ,
-.Fn MDXUpdate
-and
-.Fn MDXFinal
-instead of calling
-.Fn MDXTransform
-directly.
-.Pp
-.Fn MDXEnd
-is a wrapper for
-.Fn MDXFinal
-which converts the return value to an MDX_DIGEST_STRING_LENGTH-character
-(including the terminating '\e0')
-.Tn ASCII
-string which represents the 128 bits in hexadecimal.
-.Pp
-.Fn MDXFile
-calculates the digest of a file, and uses
-.Fn MDXEnd
-to return the result.
-If the file cannot be opened, a null pointer is returned.
-.Pp
-.Fn MDXFileChunk
-behaves like
-.Fn MDXFile
-but calculates the digest only for that portion of the file starting at
-.Fa offset
-and continuing for
-.Fa length
-bytes or until end of file is reached, whichever comes first.
-A zero
-.Fa length
-can be specified to read until end of file.
-A negative
-.Fa length
-or
-.Fa offset
-will be ignored.
-.Fn MDXData
-calculates the digest of a chunk of data in memory, and uses
-.Fn MDXEnd
-to return the result.
-.Pp
-When using
-.Fn MDXEnd ,
-.Fn MDXFile ,
-.Fn MDXFileChunk ,
-or
-.Fn MDXData ,
-the
-.Ar buf
-argument can be a null pointer, in which case the returned string
-is allocated with
-.Xr malloc 3
-and subsequently must be explicitly deallocated using
-.Xr free 3
-after use.
-If the
-.Ar buf
-argument is non-null it must point to at least MDX_DIGEST_STRING_LENGTH
-characters of buffer space.
-.Sh SEE ALSO
-.Xr cksum 1 ,
-.Xr md5 1 ,
-.Xr adler32 3 ,
-.Xr mdY 3 ,
-.Xr rmd160 3 ,
-.Xr sfv 3 ,
-.Xr sha1 3 ,
-.Xr sha2 3 ,
-.Xr suma 3 ,
-.Xr tiger 3 ,
-.Xr whirlpool 3
-.Rs
-.%A R. Rivest
-.%T The MD4 Message-Digest Algorithm
-.%O RFC 1186
-.Re
-.Rs
-.%A R. Rivest
-.%T The MD5 Message-Digest Algorithm
-.%O RFC 1321
-.Re
-.Rs
-.%A RSA Laboratories
-.%T Frequently Asked Questions About today's Cryptography
-.%O \&<http://www.rsa.com/rsalabs/faq/>
-.Re
-.Rs
-.%A H. Dobbertin
-.%T Alf Swindles Ann
-.%J CryptoBytes
-.%N 1(3):5
-.%D 1995
-.Re
-.Rs
-.%A MJ. B. Robshaw
-.%T On Recent Results for MD4 and MD5
-.%J RSA Laboratories Bulletin
-.%N 4
-.%D November 12, 1996
-.Re
-.Rs
-.%A Hans Dobbertin
-.%T Cryptanalysis of MD5 Compress
-.Re
-.Sh HISTORY
-These functions appeared in
-.Ox 2.0 .
-.Sh AUTHORS
-The original MDX routines were developed by
-.Tn RSA
-Data Security, Inc., and published in the above references.
-This code is derived from a public domain implementation written by Colin Plumb.
-.Pp
-The
-.Fn MDXEnd ,
-.Fn MDXFile ,
-.Fn MDXFileChunk ,
-and
-.Fn MDXData
-helper functions are derived from code written by Poul-Henning Kamp.
-.Sh BUGS
-Collisions have been found for the full versions of both MD4 and MD5
-as well as strong attacks against the SHA-0 and SHA-1 family.
-The use of
-.Xr sha2 3 ,
-or
-.Xr rmd160 3
-is recommended instead.
diff --git a/src/mergesort.3 b/src/mergesort.3
deleted file mode 100644
index c1979c3..0000000
--- a/src/mergesort.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/heapsort.3
diff --git a/src/nlist.3 b/src/nlist.3
deleted file mode 100644
index 25624c7..0000000
--- a/src/nlist.3
+++ /dev/null
@@ -1,78 +0,0 @@
-.\" Copyright (c) 1980, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)nlist.3	8.3 (Berkeley) 4/19/94
-.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $
-.\"
-.Dd April 19, 1994
-.Dt NLIST 3
-.Os
-.Sh NAME
-.Nm nlist
-.Nd retrieve symbol table name list from an executable file
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/nlist.h
-.Ft int
-.Fn nlist "const char *filename" "struct nlist *nl"
-.Sh DESCRIPTION
-The
-.Fn nlist
-function
-retrieves name list entries from the symbol table of an
-executable file (see
-.Xr a.out 5 ) .
-The argument
-.Fa \&nl
-is set to reference the
-beginning of the list.
-The list is preened of binary and invalid data;
-if an entry in the
-name list is valid, the
-.Fa n_type
-and
-.Fa n_value
-for the entry are copied into the list
-referenced by
-.Fa \&nl .
-No other data is copied.
-The last entry in the list is always
-.Dv NULL .
-.Sh RETURN VALUES
-The number of invalid entries is returned if successful; otherwise,
-if the file
-.Fa filename
-does not exist or is not executable, the returned value is \-1.
-.Sh SEE ALSO
-.Xr a.out 5
-.Sh HISTORY
-A
-.Fn nlist
-function appeared in
-.At v6 .
diff --git a/src/pidfile.3 b/src/pidfile.3
deleted file mode 100644
index 2f84c44..0000000
--- a/src/pidfile.3
+++ /dev/null
@@ -1,254 +0,0 @@
-.\" Copyright (c) 2005 Pawel Jakub Dawidek <pjd at FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd October 20, 2008
-.Dt PIDFILE 3
-.Os
-.Sh NAME
-.Nm pidfile_open ,
-.Nm pidfile_write ,
-.Nm pidfile_close ,
-.Nm pidfile_remove
-.Nd "library for PID files handling"
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/libutil.h
-.Ft "struct pidfh *"
-.Fn pidfile_open "const char *path" "mode_t mode" "pid_t *pidptr"
-.Ft int
-.Fn pidfile_write "struct pidfh *pfh"
-.Ft int
-.Fn pidfile_close "struct pidfh *pfh"
-.Ft int
-.Fn pidfile_remove "struct pidfh *pfh"
-.Sh DESCRIPTION
-The
-.Nm pidfile
-family of functions allows daemons to handle PID files.
-It uses
-.Xr flopen 3
-to lock a pidfile and detect already running daemons.
-.Pp
-The
-.Fn pidfile_open
-function opens (or creates) a file specified by the
-.Fa path
-argument and locks it.
-If a file can not be locked, a PID of an already running daemon is returned in
-the
-.Fa pidptr
-argument (if it is not
-.Dv NULL ) .
-The function does not write process' PID into the file here, so it can be
-used before
-.Fn fork Ns ing
-and exit with a proper error message when needed.
-If the
-.Fa path
-argument is
-.Dv NULL ,
-.Pa /var/run/ Ns Ao Va progname Ac Ns Pa .pid
-file will be used.
-.Pp
-The
-.Fn pidfile_write
-function writes process' PID into a previously opened file.
-.Pp
-The
-.Fn pidfile_close
-function closes a pidfile.
-It should be used after daemon
-.Fn fork Ns s
-to start a child process.
-.Pp
-The
-.Fn pidfile_remove
-function closes and removes a pidfile.
-.Sh RETURN VALUES
-The
-.Fn pidfile_open
-function returns a valid pointer to a
-.Vt pidfh
-structure on success, or
-.Dv NULL
-if an error occurs.
-If an error occurs,
-.Va errno
-will be set.
-.Pp
-.Rv -std pidfile_write pidfile_close pidfile_remove
-.Sh EXAMPLES
-The following example shows in which order these functions should be used.
-Note that it is safe to pass
-.Dv NULL
-to
-.Fn pidfile_write ,
-.Fn pidfile_remove
-and
-.Fn pidfile_close
-functions.
-.Bd -literal
-struct pidfh *pfh;
-pid_t otherpid, childpid;
-
-pfh = pidfile_open("/var/run/daemon.pid", 0600, &otherpid);
-if (pfh == NULL) {
-	if (errno == EEXIST) {
-		errx(EXIT_FAILURE, "Daemon already running, pid: %jd.",
-		    (intmax_t)otherpid);
-	}
-	/* If we cannot create pidfile from other reasons, only warn. */
-	warn("Cannot open or create pidfile");
-}
-
-if (daemon(0, 0) == -1) {
-	warn("Cannot daemonize");
-	pidfile_remove(pfh);
-	exit(EXIT_FAILURE);
-}
-
-pidfile_write(pfh);
-
-for (;;) {
-	/* Do work. */
-	childpid = fork();
-	switch (childpid) {
-	case -1:
-		syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno));
-		break;
-	case 0:
-		pidfile_close(pfh);
-		/* Do child work. */
-		break;
-	default:
-		syslog(LOG_INFO, "Child %jd started.", (intmax_t)childpid);
-		break;
-	}
-}
-
-pidfile_remove(pfh);
-exit(EXIT_SUCCESS);
-.Ed
-.Sh ERRORS
-The
-.Fn pidfile_open
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EEXIST
-Some process already holds the lock on the given pidfile, meaning that a
-daemon is already running.
-.It Bq Er ENAMETOOLONG
-Specified pidfile's name is too long.
-.It Bq Er EINVAL
-Some process already holds the lock on the given pidfile, but PID read
-from there is invalid.
-.It Bq Er EAGAIN
-Some process already holds the lock on the given pidfile, but the file
-is truncated.
-Most likely, the existing daemon is writing new PID into
-the file.
-.El
-.Pp
-The
-.Fn pidfile_open
-function may also fail and set
-.Va errno
-for any errors specified for the
-.Xr fstat 2 ,
-.Xr open 2 ,
-and
-.Xr read 2
-calls.
-.Pp
-The
-.Fn pidfile_write
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Improper function use.
-Probably called before
-.Fn pidfile_open .
-.El
-.Pp
-The
-.Fn pidfile_write
-function may also fail and set
-.Va errno
-for any errors specified for the
-.Xr fstat 2 ,
-.Xr ftruncate 2 ,
-and
-.Xr write 2
-calls.
-.Pp
-The
-.Fn pidfile_close
-function may fail and set
-.Va errno
-for any errors specified for the
-.Xr close 2
-and
-.Xr fstat 2
-calls.
-.Pp
-The
-.Fn pidfile_remove
-function will fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-Improper function use.
-Probably called not from the process which made
-.Fn pidfile_write .
-.El
-.Pp
-The
-.Fn pidfile_remove
-function may also fail and set
-.Va errno
-for any errors specified for the
-.Xr close 2 ,
-.Xr fstat 2 ,
-.Xr write 2 ,
-and
-.Xr unlink 2
-system calls and the
-.Xr flopen 3
-library function.
-.Sh SEE ALSO
-.Xr open 2 ,
-.Xr daemon 3 ,
-.Xr flopen 3
-.Sh AUTHORS
-.An -nosplit
-The
-.Nm pidfile
-functionality is based on ideas from
-.An John-Mark Gurney Aq jmg at FreeBSD.org .
-.Pp
-The code and manual page was written by
-.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org .
diff --git a/src/radixsort.3 b/src/radixsort.3
deleted file mode 100644
index 3884124..0000000
--- a/src/radixsort.3
+++ /dev/null
@@ -1,161 +0,0 @@
-.\" Copyright (c) 1990, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)radixsort.3	8.2 (Berkeley) 1/27/94
-.\" $FreeBSD$
-.\"
-.Dd January 27, 1994
-.Dt RADIXSORT 3
-.Os
-.Sh NAME
-.Nm radixsort , sradixsort
-.Nd radix sort
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In limits.h
-.In bsd/stdlib.h
-.Ft int
-.Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
-.Ft int
-.Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
-.Sh DESCRIPTION
-The
-.Fn radixsort
-and
-.Fn sradixsort
-functions
-are implementations of radix sort.
-.Pp
-These functions sort an array of pointers to byte strings, the initial
-member of which is referenced by
-.Fa base .
-The byte strings may contain any values; the end of each string
-is denoted by the user-specified value
-.Fa endbyte .
-.Pp
-Applications may specify a sort order by providing the
-.Fa table
-argument.
-If
-.Pf non- Dv NULL ,
-.Fa table
-must reference an array of
-.Dv UCHAR_MAX
-+ 1 bytes which contains the sort
-weight of each possible byte value.
-The end-of-string byte must have a sort weight of 0 or 255
-(for sorting in reverse order).
-More than one byte may have the same sort weight.
-The
-.Fa table
-argument
-is useful for applications which wish to sort different characters
-equally, for example, providing a table with the same weights
-for A-Z as for a-z will result in a case-insensitive sort.
-If
-.Fa table
-is NULL, the contents of the array are sorted in ascending order
-according to the
-.Tn ASCII
-order of the byte strings they reference and
-.Fa endbyte
-has a sorting weight of 0.
-.Pp
-The
-.Fn sradixsort
-function is stable, that is, if two elements compare as equal, their
-order in the sorted array is unchanged.
-The
-.Fn sradixsort
-function uses additional memory sufficient to hold
-.Fa nmemb
-pointers.
-.Pp
-The
-.Fn radixsort
-function is not stable, but uses no additional memory.
-.Pp
-These functions are variants of most-significant-byte radix sorting; in
-particular, see
-.An "D.E. Knuth" Ns 's
-.%T "Algorithm R"
-and section 5.2.5, exercise 10.
-They take linear time relative to the number of bytes in the strings.
-.Sh RETURN VALUES
-.Rv -std radixsort
-.Sh ERRORS
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value of the
-.Fa endbyte
-element of
-.Fa table
-is not 0 or 255.
-.El
-.Pp
-Additionally, the
-.Fn sradixsort
-function
-may fail and set
-.Va errno
-for any of the errors specified for the library routine
-.Xr malloc 3 .
-.Sh SEE ALSO
-.Xr sort 1 ,
-.Xr qsort 3
-.Pp
-.Rs
-.%A Knuth, D.E.
-.%D 1968
-.%B "The Art of Computer Programming"
-.%T "Sorting and Searching"
-.%V Vol. 3
-.%P pp. 170-178
-.Re
-.Rs
-.%A Paige, R.
-.%D 1987
-.%T "Three Partition Refinement Algorithms"
-.%J "SIAM J. Comput."
-.%V Vol. 16
-.%N No. 6
-.Re
-.Rs
-.%A McIlroy, P.
-.%D 1993
-.%B "Engineering Radix Sort"
-.%T "Computing Systems"
-.%V Vol. 6:1
-.%P pp. 5-27
-.Re
-.Sh HISTORY
-The
-.Fn radixsort
-function first appeared in
-.Bx 4.4 .
diff --git a/src/readpassphrase.3 b/src/readpassphrase.3
deleted file mode 100644
index 967f8d3..0000000
--- a/src/readpassphrase.3
+++ /dev/null
@@ -1,168 +0,0 @@
-.\"	$OpenBSD: readpassphrase.3,v 1.16 2005/07/22 03:16:58 jaredy Exp $
-.\"
-.\" Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller at courtesan.com>
-.\"
-.\" Permission to use, copy, modify, and distribute this software for any
-.\" purpose with or without fee is hereby granted, provided that the above
-.\" copyright notice and this permission notice appear in all copies.
-.\"
-.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-.\"
-.\" Sponsored in part by the Defense Advanced Research Projects
-.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
-.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt READPASSPHRASE 3
-.Os
-.Sh NAME
-.Nm readpassphrase
-.Nd get a passphrase from the user
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.Fd #include <bsd/readpassphrase.h>
-.Ft char *
-.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
-.Sh DESCRIPTION
-The
-.Fn readpassphrase
-function displays a prompt to, and reads in a passphrase from,
-.Pa /dev/tty .
-If this file is inaccessible
-and the
-.Dv RPP_REQUIRE_TTY
-flag is not set,
-.Fn readpassphrase
-displays the prompt on the standard error output and reads from the standard
-input.
-In this case it is generally not possible to turn off echo.
-.Pp
-Up to
-.Fa bufsiz
-- 1 characters (one is for the NUL) are read into the provided buffer
-.Fa buf .
-Any additional
-characters and the terminating newline (or return) character are discarded.
-.Pp
-.Fn readpassphrase
-takes the following optional
-.Fa flags :
-.Bd -literal -offset indent
-RPP_ECHO_OFF		turn off echo (default behavior)
-RPP_ECHO_ON		leave echo on
-RPP_REQUIRE_TTY		fail if there is no tty
-RPP_FORCELOWER		force input to lower case
-RPP_FORCEUPPER		force input to upper case
-RPP_SEVENBIT		strip the high bit from input
-RPP_STDIN		force read of passphrase from stdin
-.Ed
-.Pp
-The calling process should zero the passphrase as soon as possible to
-avoid leaving the cleartext passphrase visible in the process's address
-space.
-.Sh RETURN VALUES
-Upon successful completion,
-.Fn readpassphrase
-returns a pointer to the NUL-terminated passphrase.
-If an error is encountered, the terminal state is restored and
-a null pointer is returned.
-.Sh FILES
-.Bl -tag -width /dev/tty -compact
-.It Pa /dev/tty
-.El
-.Sh EXAMPLES
-The following code fragment will read a passphrase from
-.Pa /dev/tty
-into the buffer
-.Fa passbuf .
-.Bd -literal -offset indent
-char passbuf[1024];
-
-\&...
-
-if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
-    RPP_REQUIRE_TTY) == NULL)
-	errx(1, "unable to read passphrase");
-
-if (compare(transform(passbuf), epass) != 0)
-	errx(1, "bad passphrase");
-
-\&...
-
-memset(passbuf, 0, sizeof(passbuf));
-.Ed
-.Sh ERRORS
-.Bl -tag -width Er
-.It Bq Er EINTR
-The
-.Fn readpassphrase
-function was interrupted by a signal.
-.It Bq Er EINVAL
-The
-.Ar bufsiz
-argument was zero.
-.It Bq Er EIO
-The process is a member of a background process attempting to read
-from its controlling terminal, the process is ignoring or blocking
-the
-.Dv SIGTTIN
-signal, or the process group is orphaned.
-.It Bq Er EMFILE
-The process has already reached its limit for open file descriptors.
-.It Bq Er ENFILE
-The system file table is full.
-.It Bq Er ENOTTY
-There is no controlling terminal and the
-.Dv RPP_REQUIRE_TTY
-flag was specified.
-.El
-.Sh SIGNALS
-.Fn readpassphrase
-will catch the following signals:
-.Bd -literal -offset indent
-SIGALRM		SIGHUP		SIGINT
-SIGPIPE		SIGQUIT		SIGTERM
-SIGTSTP		SIGTTIN		SIGTTOU
-.Ed
-.Pp
-When one of the above signals is intercepted, terminal echo will
-be restored if it had previously been turned off.
-If a signal handler was installed for the signal when
-.Fn readpassphrase
-was called, that handler is then executed.
-If no handler was previously installed for the signal then the
-default action is taken as per
-.Xr sigaction 2 .
-.Pp
-The
-.Dv SIGTSTP ,
-.Dv SIGTTIN ,
-and
-.Dv SIGTTOU
-signals (stop signals generated from keyboard or due to terminal I/O
-from a background process) are treated specially.
-When the process is resumed after it has been stopped,
-.Fn readpassphrase
-will reprint the prompt and the user may then enter a passphrase.
-.Sh SEE ALSO
-.Xr sigaction 2 ,
-.Xr getpass 3
-.Sh STANDARDS
-The
-.Fn readpassphrase
-function is an
-.Ox
-extension and should not be used if portability is desired.
-.Sh HISTORY
-The
-.Fn readpassphrase
-function first appeared in
-.Ox 2.9 .
diff --git a/src/reallocf.3 b/src/reallocf.3
deleted file mode 100644
index 99152b6..0000000
--- a/src/reallocf.3
+++ /dev/null
@@ -1,107 +0,0 @@
-.\" Copyright (c) 1980, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the American National Standards Committee X3, on Information
-.\" Processing Systems.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)malloc.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $
-.\"
-.Dd September 26, 2009
-.Dt MALLOC 3
-.Os
-.Sh NAME
-.Nm reallocf
-.Nd general purpose memory allocation functions
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/stdlib.h
-.Ft void *
-.Fn reallocf "void *ptr" "size_t size"
-.Sh DESCRIPTION
-The
-.Fn reallocf
-function changes the size of the previously allocated memory referenced by
-.Fa ptr
-to
-.Fa size
-bytes.
-The contents of the memory are unchanged up to the lesser of the new and
-old sizes.
-If the new size is larger,
-the contents of the newly allocated portion of the memory are undefined.
-Upon success, the memory referenced by
-.Fa ptr
-is freed and a pointer to the newly allocated memory is returned.
-Note that
-.Fn reallocf
-may move the memory allocation, resulting in a different return value than
-.Fa ptr .
-If
-.Fa ptr
-is
-.Dv NULL ,
-the
-.Fn reallocf
-function behaves identically to
-.Fn malloc
-for the specified size.
-Upon failure, when the requested memory cannot be allocated, the passed pointer
-is freed to ease the problems with traditional coding styles for
-.Fn reallocf
-causing memory leaks in libraries.
-.Sh RETURN VALUES
-The
-.Fn reallocf
-function returns a pointer, possibly identical to
-.Fa ptr ,
-to the allocated memory
-if successful; otherwise a
-.Dv NULL
-pointer is returned, and
-.Va errno
-is set to
-.Er ENOMEM
-if the error was the result of an allocation failure.
-The buffer is deallocated in this case.
-.Sh SEE ALSO
-.Xr brk 2 ,
-.Xr mmap 2 ,
-.Xr alloca 3 ,
-.Xr calloc 3 ,
-.Xr free 3 ,
-.Xr malloc 3 ,
-.Xr posix_memalign 3 ,
-.Xr realloc 3 ,
-.Sh HISTORY
-The
-.Fn reallocf
-function first appeared in
-.Fx 3.0 .
diff --git a/src/setmode.3 b/src/setmode.3
deleted file mode 100644
index ae7c568..0000000
--- a/src/setmode.3
+++ /dev/null
@@ -1,115 +0,0 @@
-.\" Copyright (c) 1989, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)setmode.3	8.2 (Berkeley) 4/28/95
-.\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $
-.\"
-.Dd April 28, 1995
-.Dt SETMODE 3
-.Os
-.Sh NAME
-.Nm getmode ,
-.Nm setmode
-.Nd modify mode bits
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/unistd.h
-.Ft mode_t
-.Fn getmode "const void *set" "mode_t mode"
-.Ft void *
-.Fn setmode "const char *mode_str"
-.Sh DESCRIPTION
-The
-.Fn getmode
-function
-returns a copy of the file permission bits
-.Fa mode
-as altered by the values pointed to by
-.Fa set .
-While only the mode bits are altered, other parts of the file mode
-may be examined.
-.Pp
-The
-.Fn setmode
-function
-takes an absolute (octal) or symbolic value, as described in
-.Xr chmod 1 ,
-as an argument
-and returns a pointer to mode values to be supplied to
-.Fn getmode .
-Because some of the symbolic values are relative to the file
-creation mask,
-.Fn setmode
-may call
-.Xr umask 2 .
-If this occurs, the file creation mask will be restored before
-.Fn setmode
-returns.
-If the calling program changes the value of its file creation mask
-after calling
-.Fn setmode ,
-.Fn setmode
-must be called again if
-.Fn getmode
-is to modify future file modes correctly.
-.Pp
-If the mode passed to
-.Fn setmode
-is invalid or if memory cannot be allocated for the return value,
-.Fn setmode
-returns
-.Dv NULL .
-.Pp
-The value returned from
-.Fn setmode
-is obtained from
-.Fn malloc
-and should be returned to the system with
-.Fn free
-when the program is done with it, generally after a call to
-.Fn getmode .
-.Sh ERRORS
-The
-.Fn setmode
-function
-may fail and set errno for any of the errors specified for the library
-routine
-.Xr malloc 3 .
-.Sh SEE ALSO
-.Xr chmod 1 ,
-.Xr stat 2 ,
-.Xr umask 2 ,
-.Xr malloc 3
-.Sh HISTORY
-The
-.Fn getmode
-and
-.Fn setmode
-functions first appeared in
-.Bx 4.4 .
diff --git a/src/sradixsort.3 b/src/sradixsort.3
deleted file mode 100644
index 86a95a3..0000000
--- a/src/sradixsort.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/radixsort.3
diff --git a/src/strlcat.3 b/src/strlcat.3
deleted file mode 100644
index d968886..0000000
--- a/src/strlcat.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/strlcpy.3
diff --git a/src/strlcpy.3 b/src/strlcpy.3
deleted file mode 100644
index bf14b4f..0000000
--- a/src/strlcpy.3
+++ /dev/null
@@ -1,191 +0,0 @@
-.\" $OpenBSD: strlcpy.3,v 1.18 2005/08/06 03:24:19 jaredy Exp $
-.\"
-.\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller at courtesan.com>
-.\"
-.\" Permission to use, copy, modify, and distribute this software for any
-.\" purpose with or without fee is hereby granted, provided that the above
-.\" copyright notice and this permission notice appear in all copies.
-.\"
-.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt STRLCPY 3
-.Os
-.Sh NAME
-.Nm strlcpy ,
-.Nm strlcat
-.Nd size-bounded string copying and concatenation
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/string.h
-.Ft size_t
-.Fn strlcpy "char *dst" "const char *src" "size_t size"
-.Ft size_t
-.Fn strlcat "char *dst" "const char *src" "size_t size"
-.Sh DESCRIPTION
-The
-.Fn strlcpy
-and
-.Fn strlcat
-functions copy and concatenate strings respectively.
-They are designed
-to be safer, more consistent, and less error prone replacements for
-.Xr strncpy 3
-and
-.Xr strncat 3 .
-Unlike those functions,
-.Fn strlcpy
-and
-.Fn strlcat
-take the full size of the buffer (not just the length) and guarantee to
-NUL-terminate the result (as long as
-.Fa size
-is larger than 0 or, in the case of
-.Fn strlcat ,
-as long as there is at least one byte free in
-.Fa dst ) .
-Note that a byte for the NUL should be included in
-.Fa size .
-Also note that
-.Fn strlcpy
-and
-.Fn strlcat
-only operate on true
-.Dq C
-strings.
-This means that for
-.Fn strlcpy
-.Fa src
-must be NUL-terminated and for
-.Fn strlcat
-both
-.Fa src
-and
-.Fa dst
-must be NUL-terminated.
-.Pp
-The
-.Fn strlcpy
-function copies up to
-.Fa size
-- 1 characters from the NUL-terminated string
-.Fa src
-to
-.Fa dst ,
-NUL-terminating the result.
-.Pp
-The
-.Fn strlcat
-function appends the NUL-terminated string
-.Fa src
-to the end of
-.Fa dst .
-It will append at most
-.Fa size
-- strlen(dst) - 1 bytes, NUL-terminating the result.
-.Sh RETURN VALUES
-The
-.Fn strlcpy
-and
-.Fn strlcat
-functions return the total length of the string they tried to create.
-For
-.Fn strlcpy
-that means the length of
-.Fa src .
-For
-.Fn strlcat
-that means the initial length of
-.Fa dst
-plus
-the length of
-.Fa src .
-While this may seem somewhat confusing, it was done to make
-truncation detection simple.
-.Pp
-Note, however, that if
-.Fn strlcat
-traverses
-.Fa size
-characters without finding a NUL, the length of the string is considered
-to be
-.Fa size
-and the destination string will not be NUL-terminated (since there was
-no space for the NUL).
-This keeps
-.Fn strlcat
-from running off the end of a string.
-In practice this should not happen (as it means that either
-.Fa size
-is incorrect or that
-.Fa dst
-is not a proper
-.Dq C
-string).
-The check exists to prevent potential security problems in incorrect code.
-.Sh EXAMPLES
-The following code fragment illustrates the simple case:
-.Bd -literal -offset indent
-char *s, *p, buf[BUFSIZ];
-
-\&...
-
-(void)strlcpy(buf, s, sizeof(buf));
-(void)strlcat(buf, p, sizeof(buf));
-.Ed
-.Pp
-To detect truncation, perhaps while building a pathname, something
-like the following might be used:
-.Bd -literal -offset indent
-char *dir, *file, pname[MAXPATHLEN];
-
-\&...
-
-if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
-	goto toolong;
-if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
-	goto toolong;
-.Ed
-.Pp
-Since it is known how many characters were copied the first time, things
-can be sped up a bit by using a copy instead of an append:
-.Bd -literal -offset indent
-char *dir, *file, pname[MAXPATHLEN];
-size_t n;
-
-\&...
-
-n = strlcpy(pname, dir, sizeof(pname));
-if (n >= sizeof(pname))
-	goto toolong;
-if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n)
-	goto toolong;
-.Ed
-.Pp
-However, one may question the validity of such optimizations, as they
-defeat the whole purpose of
-.Fn strlcpy
-and
-.Fn strlcat .
-As a matter of fact, the first version of this manual page got it wrong.
-.Sh SEE ALSO
-.Xr snprintf 3 ,
-.Xr strncat 3 ,
-.Xr strncpy 3
-.Sh HISTORY
-The
-.Fn strlcpy
-and
-.Fn strlcat
-functions first appeared in
-.Ox 2.4 ,
-and made their appearance in
-.Fx 3.3 .
diff --git a/src/strmode.3 b/src/strmode.3
deleted file mode 100644
index 70264c0..0000000
--- a/src/strmode.3
+++ /dev/null
@@ -1,145 +0,0 @@
-.\" Copyright (c) 1990, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)strmode.3	8.3 (Berkeley) 7/28/94
-.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
-.\"
-.Dd July 28, 1994
-.Dt STRMODE 3
-.Os
-.Sh NAME
-.Nm strmode
-.Nd convert inode status information into a symbolic string
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/string.h
-.Ft void
-.Fn strmode "mode_t mode" "char *bp"
-.Sh DESCRIPTION
-The
-.Fn strmode
-function
-converts a file
-.Fa mode
-(the type and permission information associated with an inode, see
-.Xr stat 2 )
-into a symbolic string which is stored in the location referenced by
-.Fa bp .
-This stored string is eleven characters in length plus a trailing
-.Dv NUL .
-.Pp
-The first character is the inode type, and will be one of the following:
-.Pp
-.Bl -tag -width flag -offset indent -compact
-.It \-
-regular file
-.It b
-block special
-.It c
-character special
-.It d
-directory
-.It l
-symbolic link
-.It p
-fifo
-.It s
-socket
-.It w
-whiteout
-.It ?
-unknown inode type
-.El
-.Pp
-The next nine characters encode three sets of permissions, in three
-characters each.
-The first three characters are the permissions for the owner of the
-file, the second three for the group the file belongs to, and the
-third for the ``other'', or default, set of users.
-.Pp
-Permission checking is done as specifically as possible.
-If read permission is denied to the owner of a file in the first set
-of permissions, the owner of the file will not be able to read the file.
-This is true even if the owner is in the file's group and the group
-permissions allow reading or the ``other'' permissions allow reading.
-.Pp
-If the first character of the three character set is an ``r'', the file is
-readable for that set of users; if a dash ``\-'', it is not readable.
-.Pp
-If the second character of the three character set is a ``w'', the file is
-writable for that set of users; if a dash ``\-'', it is not writable.
-.Pp
-The third character is the first of the following characters that apply:
-.Bl -tag -width xxxx
-.It S
-If the character is part of the owner permissions and the file is not
-executable or the directory is not searchable by the owner, and the
-set-user-id bit is set.
-.It S
-If the character is part of the group permissions and the file is not
-executable or the directory is not searchable by the group, and the
-set-group-id bit is set.
-.It T
-If the character is part of the other permissions and the file is not
-executable or the directory is not searchable by others, and the ``sticky''
-.Pq Dv S_ISVTX
-bit is set.
-.It s
-If the character is part of the owner permissions and the file is
-executable or the directory searchable by the owner, and the set-user-id
-bit is set.
-.It s
-If the character is part of the group permissions and the file is
-executable or the directory searchable by the group, and the set-group-id
-bit is set.
-.It t
-If the character is part of the other permissions and the file is
-executable or the directory searchable by others, and the ``sticky''
-.Pq Dv S_ISVTX
-bit is set.
-.It x
-The file is executable or the directory is searchable.
-.It \-
-None of the above apply.
-.El
-.Pp
-The last character is a plus sign ``+'' if any there are any alternate
-or additional access control methods associated with the inode, otherwise
-it will be a space.
-.Sh SEE ALSO
-.Xr chmod 1 ,
-.Xr find 1 ,
-.Xr stat 2 ,
-.Xr getmode 3 ,
-.Xr setmode 3
-.Sh HISTORY
-The
-.Fn strmode
-function first appeared in
-.Bx 4.4 .
diff --git a/src/strtonum.3 b/src/strtonum.3
deleted file mode 100644
index 42674f0..0000000
--- a/src/strtonum.3
+++ /dev/null
@@ -1,159 +0,0 @@
-.\" Copyright (c) 2004 Ted Unangst
-.\"
-.\" Permission to use, copy, modify, and distribute this software for any
-.\" purpose with or without fee is hereby granted, provided that the above
-.\" copyright notice and this permission notice appear in all copies.
-.\"
-.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-.\"
-.\" $OpenBSD: strtonum.3,v 1.12 2005/10/26 11:37:58 jmc Exp $
-.\" $FreeBSD$
-.\"
-.Dd April 29, 2004
-.Dt STRTONUM 3
-.Os
-.Sh NAME
-.Nm strtonum
-.Nd "reliably convert string value to an integer"
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In limits.h
-.In bsd/stdlib.h
-.Ft long long
-.Fo strtonum
-.Fa "const char *nptr"
-.Fa "long long minval"
-.Fa "long long maxval"
-.Fa "const char **errstr"
-.Fc
-.Sh DESCRIPTION
-The
-.Fn strtonum
-function converts the string in
-.Fa nptr
-to a
-.Vt "long long"
-value.
-The
-.Fn strtonum
-function was designed to facilitate safe, robust programming
-and overcome the shortcomings of the
-.Xr atoi 3
-and
-.Xr strtol 3
-family of interfaces.
-.Pp
-The string may begin with an arbitrary amount of whitespace
-(as determined by
-.Xr isspace 3 )
-followed by a single optional
-.Ql +
-or
-.Ql -
-sign.
-.Pp
-The remainder of the string is converted to a
-.Vt "long long"
-value according to base 10.
-.Pp
-The value obtained is then checked against the provided
-.Fa minval
-and
-.Fa maxval
-bounds.
-If
-.Fa errstr
-is non-null,
-.Fn strtonum
-stores an error string in
-.Fa *errstr
-indicating the failure.
-.Sh RETURN VALUES
-The
-.Fn strtonum
-function returns the result of the conversion,
-unless the value would exceed the provided bounds or is invalid.
-On error, 0 is returned,
-.Va errno
-is set, and
-.Fa errstr
-will point to an error message.
-On success,
-.Fa *errstr
-will be set to
-.Dv NULL ;
-this fact can be used to differentiate
-a successful return of 0 from an error.
-.Sh EXAMPLES
-Using
-.Fn strtonum
-correctly is meant to be simpler than the alternative functions.
-.Bd -literal -offset indent
-int iterations;
-const char *errstr;
-
-iterations = strtonum(optarg, 1, 64, &errstr);
-if (errstr)
-	errx(1, "number of iterations is %s: %s", errstr, optarg);
-.Ed
-.Pp
-The above example will guarantee that the value of iterations is between
-1 and 64 (inclusive).
-.Sh ERRORS
-.Bl -tag -width Er
-.It Bq Er ERANGE
-The given string was out of range.
-.It Bq Er EINVAL
-The given string did not consist solely of digit characters.
-.It Bq Er EINVAL
-The supplied
-.Fa minval
-was larger than
-.Fa maxval .
-.El
-.Pp
-If an error occurs,
-.Fa errstr
-will be set to one of the following strings:
-.Pp
-.Bl -tag -width ".Li too large" -compact
-.It Li "too large"
-The result was larger than the provided maximum value.
-.It Li "too small"
-The result was smaller than the provided minimum value.
-.It Li invalid
-The string did not consist solely of digit characters.
-.El
-.Sh SEE ALSO
-.Xr atof 3 ,
-.Xr atoi 3 ,
-.Xr atol 3 ,
-.Xr atoll 3 ,
-.Xr sscanf 3 ,
-.Xr strtod 3 ,
-.Xr strtol 3 ,
-.Xr strtoul 3
-.Sh STANDARDS
-The
-.Fn strtonum
-function is a
-.Bx
-extension.
-The existing alternatives, such as
-.Xr atoi 3
-and
-.Xr strtol 3 ,
-are either impossible or difficult to use safely.
-.Sh HISTORY
-The
-.Fn strtonum
-function first appeared in
-.Ox 3.6 .
diff --git a/src/unvis.3 b/src/unvis.3
deleted file mode 100644
index 5e01f88..0000000
--- a/src/unvis.3
+++ /dev/null
@@ -1,198 +0,0 @@
-.\"	$OpenBSD: unvis.3,v 1.15 2005/07/22 03:16:58 jaredy Exp $
-.\"
-.\" Copyright (c) 1989, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt UNVIS 3
-.Os
-.Sh NAME
-.Nm unvis ,
-.Nm strunvis ,
-.Nm strnunvis
-.Nd decode a visual representation of characters
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In bsd/vis.h
-.Ft int
-.Fn unvis "char *cp" "char c" "int *astate" "int flag"
-.Ft int
-.Fn strunvis "char *dst" "char *src"
-.Ft ssize_t
-.Fn strnunvis "char *dst" "char *src" "size_t size"
-.Sh DESCRIPTION
-The
-.Fn unvis ,
-.Fn strunvis
-and
-.Fn strnunvis
-functions are used to decode a visual representation of characters,
-as produced by the
-.Xr vis 3
-function, back into the original form.
-.Fn unvis
-is called with successive characters in
-.Fa c
-until a valid
-sequence is recognized, at which time the decoded character is
-available at the character pointed to by
-.Fa cp .
-.Pp
-.Fn strunvis
-decodes the characters pointed to by
-.Fa src
-into the buffer pointed to by
-.Fa dst .
-.Pp
-.Fn strnunvis
-decodes the characters pointed to by
-.Fa src
-into the buffer pointed to by
-.Fa dst ,
-writing a maximum of
-.Fa size
-bytes.
-The
-.Fn strunvis
-function simply copies
-.Fa src
-to
-.Fa dst ,
-decoding any escape sequences along the way,
-and returns the number of characters placed into
-.Fa dst ,
-or \-1 if an
-invalid escape sequence was detected.
-The size of
-.Fa dst
-should be
-equal to the size of
-.Fa src
-(that is, no expansion takes place during decoding).
-.Fn strunvis
-terminates the destination string with a trailing NUL byte;
-.Fn strnunvis
-does so if
-.Fa size
-is larger than 0.
-.Pp
-The
-.Fn unvis
-function implements a state machine that can be used to decode an arbitrary
-stream of bytes.
-All state associated with the bytes being decoded is stored outside the
-.Fn unvis
-function (that is, a pointer to the state is passed in), so
-calls decoding different streams can be freely intermixed.
-To start decoding a stream of bytes, first initialize an integer
-to zero.
-Call
-.Fn unvis
-with each successive byte, along with a pointer
-to this integer, and a pointer to a destination character.
-.Sh RETURN VALUES
-The
-.Fn unvis
-function has several return codes that must be handled properly.
-They are:
-.Bl -tag -width UNVIS_VALIDPUSH
-.It Li \&0 (zero)
-Another character is necessary; nothing has been recognized yet.
-.It Dv UNVIS_VALID
-A valid character has been recognized and is available at the location
-pointed to by
-.Fa cp .
-.It Dv UNVIS_VALIDPUSH
-A valid character has been recognized and is available at the location
-pointed to by
-.Fa cp ;
-however, the character currently passed in should be passed in again.
-.It Dv UNVIS_NOCHAR
-A valid sequence was detected, but no character was produced.
-This return code is necessary to indicate a logical break between characters.
-.It Dv UNVIS_SYNBAD
-An invalid escape sequence was detected, or the decoder is in an
-unknown state.
-The decoder is placed into the starting state.
-.El
-.Pp
-When all bytes in the stream have been processed, call
-.Fn unvis
-one more time with
-.Fa flag
-set to
-.Dv UNVIS_END
-to extract any remaining character (the character passed in is ignored).
-.Pp
-The
-.Fn strunvis
-function returns the number of bytes written (not counting
-the trailing NUL byte) or \-1 if an error occurred.
-.Pp
-The
-.Fn strnunvis
-function returns the number of bytes (not counting the trailing NUL byte)
-that would be needed to fully convert the input string, or \-1 if an
-error occurred.
-.Sh EXAMPLES
-The following code fragment illustrates a proper use of
-.Fn unvis .
-.Bd -literal -offset indent
-int state = 0;
-char out;
-
-while ((ch = getchar()) != EOF) {
-again:
-	switch(unvis(&out, ch, &state, 0)) {
-	case 0:
-	case UNVIS_NOCHAR:
-		break;
-	case UNVIS_VALID:
-		(void) putchar(out);
-		break;
-	case UNVIS_VALIDPUSH:
-		(void) putchar(out);
-		goto again;
-	case UNVIS_SYNBAD:
-		(void)fprintf(stderr, "bad sequence!\en");
-		exit(1);
-	}
-}
-if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID)
-	(void) putchar(out);
-.Ed
-.Sh SEE ALSO
-.Xr unvis 1 ,
-.Xr vis 1 ,
-.Xr vis 3
-.Sh HISTORY
-The
-.Fn unvis
-function first appeared in
-.Bx 4.4 .
diff --git a/src/vis.3 b/src/vis.3
deleted file mode 100644
index 65548f0..0000000
--- a/src/vis.3
+++ /dev/null
@@ -1,321 +0,0 @@
-.\"	$OpenBSD: vis.3,v 1.23 2005/08/28 19:51:27 millert Exp $
-.\"
-.\" Copyright (c) 1989, 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt VIS 3
-.Os
-.Sh NAME
-.Nm vis ,
-.Nm strvis ,
-.Nm strnvis ,
-.Nm strvisx
-.Nd visually encode characters
-.Sh LIBRARY
-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
-.Lb libbsd
-.Sh SYNOPSIS
-.In stdlib.h
-.In bsd/vis.h
-.Ft char *
-.Fn vis "char *dst" "int c" "int flag" "int nextc"
-.Ft int
-.Fn strvis "char *dst" "const char *src" "int flag"
-.Ft int
-.Fn strnvis "char *dst" "const char *src" "size_t size" "int flag"
-.Ft int
-.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
-.Sh DESCRIPTION
-The
-.Fn vis
-function copies into
-.Fa dst
-a string which represents the character
-.Fa c .
-If
-.Fa c
-needs no encoding, it is copied in unaltered.
-The string is NUL terminated and a pointer to the end of the string is
-returned.
-The maximum length of any encoding is four
-characters (not including the trailing NUL);
-thus, when
-encoding a set of characters into a buffer, the size of the buffer should
-be four times the number of characters encoded, plus one for the trailing
-NUL.
-The
-.Fa flag
-parameter is used for altering the default range of
-characters considered for encoding and for altering the visual
-representation.
-The additional character,
-.Fa nextc ,
-is only used when selecting the
-.Dv VIS_CSTYLE
-encoding format (explained below).
-.Pp
-The
-.Fn strvis ,
-.Fn strnvis
-and
-.Fn strvisx
-functions copy into
-.Fa dst
-a visual representation of
-the string
-.Fa src .
-The
-.Fn strvis
-function encodes characters from
-.Fa src
-up to the first NUL.
-The
-.Fn strnvis
-function encodes characters from
-.Fa src
-up to the first NUL or the end of
-.Fa dst ,
-as indicated by
-.Fa size .
-The
-.Fn strvisx
-function encodes exactly
-.Fa len
-characters from
-.Fa src
-(this
-is useful for encoding a block of data that may contain NULs).
-All three forms NUL terminate
-.Fa dst ,
-except for
-.Fn strnvis
-when
-.Fa size
-is zero, in which case
-.Fa dst
-is not touched.
-For
-.Fn strvis
-and
-.Fn strvisx ,
-the size of
-.Fa dst
-must be four times the number
-of characters encoded from
-.Fa src
-(plus one for the NUL).
-.Fn strvis
-and
-.Fn strvisx
-return the number of characters in
-.Fa dst
-(not including the trailing NUL).
-.Fn strnvis
-returns the length that
-.Fa dst
-would become if it were of unlimited size (similar to
-.Xr snprintf 3
-or
-.Xr strlcpy 3 ) .
-This can be used to detect truncation but it also means that
-the return value of
-.Fn strnvis
-must not be used without checking it against
-.Fa size .
-.Pp
-The encoding is a unique, invertible representation composed entirely of
-graphic characters; it can be decoded back into the original form using
-the
-.Xr unvis 3
-or
-.Xr strunvis 3
-functions.
-.Pp
-There are two parameters that can be controlled: the range of
-characters that are encoded, and the type
-of representation used.
-By default, all non-graphic characters
-except space, tab, and newline are encoded
-(see
-.Xr isgraph 3 ) .
-The following flags
-alter this:
-.Bl -tag -width VIS_WHITEX
-.It Dv VIS_GLOB
-Also encode magic characters recognized by
-.Xr glob 3
-.Pf ( Ql * ,
-.Ql \&? ,
-.Ql \&[ )
-and
-.Ql # .
-.It Dv VIS_SP
-Also encode space.
-.It Dv VIS_TAB
-Also encode tab.
-.It Dv VIS_NL
-Also encode newline.
-.It Dv VIS_WHITE
-Synonym for
-.Dv VIS_SP
-\&|
-.Dv VIS_TAB
-\&|
-.Dv VIS_NL .
-.It Dv VIS_SAFE
-Only encode
-.Dq unsafe
-characters.
-These are control characters which may cause common terminals to perform
-unexpected functions.
-Currently this form allows space,
-tab, newline, backspace, bell, and return -- in addition
-to all graphic characters -- unencoded.
-.El
-.Pp
-There are three forms of encoding.
-All forms use the backslash
-.Ql \e
-character to introduce a special
-sequence; two backslashes are used to represent a real backslash.
-These are the visual formats:
-.Bl -tag -width VIS_CSTYLE
-.It (default)
-Use an
-.Ql M
-to represent meta characters (characters with the 8th
-bit set), and use a caret
-.Ql ^
-to represent control characters (see
-.Xr iscntrl 3 ) .
-The following formats are used:
-.Bl -tag -width xxxxx
-.It Dv \e^C
-Represents the control character
-.Ql C .
-Spans characters
-.Ql \e000
-through
-.Ql \e037 ,
-and
-.Ql \e177
-(as
-.Ql \e^? ) .
-.It Dv \eM-C
-Represents character
-.Ql C
-with the 8th bit set.
-Spans characters
-.Ql \e241
-through
-.Ql \e376 .
-.It Dv \eM^C
-Represents control character
-.Ql C
-with the 8th bit set.
-Spans characters
-.Ql \e200
-through
-.Ql \e237 ,
-and
-.Ql \e377
-(as
-.Ql \eM^? ) .
-.It Dv \e040
-Represents
-.Tn ASCII
-space.
-.It Dv \e240
-Represents Meta-space.
-.El
-.Pp
-.It Dv VIS_CSTYLE
-Use C-style backslash sequences to represent standard non-printable
-characters.
-The following sequences are used to represent the indicated characters:
-.Bd -unfilled -offset indent
-.Li \ea Tn  - BEL No (007)
-.Li \eb Tn  - BS No (010)
-.Li \ef Tn  - NP No (014)
-.Li \en Tn  - NL No (012)
-.Li \er Tn  - CR No (015)
-.Li \es Tn  - SP No (040)
-.Li \et Tn  - HT No (011)
-.Li \ev Tn  - VT No (013)
-.Li \e0 Tn  - NUL No (000)
-.Ed
-.Pp
-When using this format, the
-.Fa nextc
-parameter is looked at to determine
-if a NUL character can be encoded as
-.Ql \e0
-instead of
-.Ql \e000 .
-If
-.Fa nextc
-is an octal digit, the latter representation is used to
-avoid ambiguity.
-.It Dv VIS_OCTAL
-Use a three digit octal sequence.
-The form is
-.Ql \eddd
-where
-.Ar d
-represents an octal digit.
-.El
-.Pp
-There is one additional flag,
-.Dv VIS_NOSLASH ,
-which inhibits the
-doubling of backslashes and the backslash before the default
-format (that is, control characters are represented by
-.Ql ^C
-and
-meta characters as
-.Ql M-C ) .
-With this flag set, the encoding is
-ambiguous and non-invertible.
-.Sh SEE ALSO
-.Xr unvis 1 ,
-.Xr vis 1 ,
-.Xr snprintf 3 ,
-.Xr strlcpy 3 ,
-.Xr unvis 3
-.Sh HISTORY
-The
-.Fn vis ,
-.Fn strvis
-and
-.Fn strvisx
-functions first appeared in
-.Bx 4.4 .
-The
-.Fn strnvis
-function first appeared in
-.Ox 2.9 .
commit 93321224f66d65acfade35305c454d5887fc9f07
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Dec 11 07:57:05 2011 +0100

    Rename version script from Versions to libbsd.map

diff --git a/Makefile b/Makefile
index aa3acb5..42b1bb0 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ $(LIB_SHARED): $(LIB_SHARED_OBJS)
 	$(LINK) \
 	  -shared \
 	  -Wl,-soname -Wl,$(LIB_SONAME) \
-	  -Wl,--version-script=Versions \
+	  -Wl,--version-script=libbsd.map \
 	  -o $@ $^
 
 .PHONY: ChangeLog
diff --git a/Versions b/Versions
deleted file mode 100644
index 39e6ea9..0000000
--- a/Versions
+++ /dev/null
@@ -1,91 +0,0 @@
-LIBBSD_0.0 {
-  global:
-    arc4random;
-    arc4random_stir;
-    arc4random_addrandom;
-
-    bsd_getopt;
-    optreset;
-
-    errc;
-    warnc;
-    verrc;
-    vwarnc;
-
-    fgetln;
-    fmtcheck;
-    heapsort;
-    humanize_number;
-
-    inet_net_pton; /* XXX: Already provided by glibc, remove. */
-
-    getprogname;
-    setprogname;
-
-    strlcpy;
-    strlcat;
-
-    setmode;
-    getmode;
-
-    vis;
-    strvis;
-    strvisx;
-    unvis;
-    strunvis;
-    strunvisx;
-
-    MD5Init;
-    MD5Update;
-    MD5Pad;
-    MD5Final;
-    MD5Transform;
-    MD5End;
-    MD5File;
-    MD5FileChunk;
-    MD5Data;
-
-  local:
-    *;
-};
-
-LIBBSD_0.1 {
-    strmode;
-
-    __fdnlist; /* Private symbol, but libkvm uses it. */
-    nlist;
-} LIBBSD_0.0;
-
-LIBBSD_0.2 {
-    strtonum;
-
-    strnvis;
-    strnunvis;
-
-    dehumanize_number;
-
-    readpassphrase;
-
-    flopen;
-
-    pidfile_open;
-    pidfile_write;
-    pidfile_close;
-    pidfile_remove;
-
-    setproctitle;
-
-    arc4random_buf;
-    arc4random_uniform;
-} LIBBSD_0.1;
-
-LIBBSD_0.3 {
-    reallocf;
-    getpeereid;
-
-    mergesort;
-    radixsort;
-    sradixsort;
-
-    fpurge;
-} LIBBSD_0.2;
diff --git a/libbsd.map b/libbsd.map
new file mode 100644
index 0000000..39e6ea9
--- /dev/null
+++ b/libbsd.map
@@ -0,0 +1,91 @@
+LIBBSD_0.0 {
+  global:
+    arc4random;
+    arc4random_stir;
+    arc4random_addrandom;
+
+    bsd_getopt;
+    optreset;
+
+    errc;
+    warnc;
+    verrc;
+    vwarnc;
+
+    fgetln;
+    fmtcheck;
+    heapsort;
+    humanize_number;
+
+    inet_net_pton; /* XXX: Already provided by glibc, remove. */
+
+    getprogname;
+    setprogname;
+
+    strlcpy;
+    strlcat;
+
+    setmode;
+    getmode;
+
+    vis;
+    strvis;
+    strvisx;
+    unvis;
+    strunvis;
+    strunvisx;
+
+    MD5Init;
+    MD5Update;
+    MD5Pad;
+    MD5Final;
+    MD5Transform;
+    MD5End;
+    MD5File;
+    MD5FileChunk;
+    MD5Data;
+
+  local:
+    *;
+};
+
+LIBBSD_0.1 {
+    strmode;
+
+    __fdnlist; /* Private symbol, but libkvm uses it. */
+    nlist;
+} LIBBSD_0.0;
+
+LIBBSD_0.2 {
+    strtonum;
+
+    strnvis;
+    strnunvis;
+
+    dehumanize_number;
+
+    readpassphrase;
+
+    flopen;
+
+    pidfile_open;
+    pidfile_write;
+    pidfile_close;
+    pidfile_remove;
+
+    setproctitle;
+
+    arc4random_buf;
+    arc4random_uniform;
+} LIBBSD_0.1;
+
+LIBBSD_0.3 {
+    reallocf;
+    getpeereid;
+
+    mergesort;
+    radixsort;
+    sradixsort;
+
+    fpurge;
+} LIBBSD_0.2;
commit 2fb7200d4505dbd4ec44c9937e86652a30eb782e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Oct 23 19:27:44 2011 +0200

    Fix typos in source comments
    
    Found by codespell.

diff --git a/src/heapsort.c b/src/heapsort.c
index 79f98d4..2479cb0 100644
--- a/src/heapsort.c
+++ b/src/heapsort.c
@@ -86,7 +86,7 @@
  * Select the top of the heap and 'heapify'.  Since by far the most expensive
  * action is the call to the compar function, a considerable optimization
  * in the average case can be achieved due to the fact that k, the displaced
- * elememt, is ususally quite small, so it would be preferable to first
+ * elememt, is usually quite small, so it would be preferable to first
  * heapify, always maintaining the invariant that the larger child is copied
  * over its parent's record.
  *
diff --git a/src/nlist.c b/src/nlist.c
index 0fcf324..7f9ed96 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -138,7 +138,7 @@ __aout_fdnlist(fd, list)
 
 	/*
 	 * Map the whole a.out file into our address space.
-	 * We then find the string table withing this area.
+	 * We then find the string table within this area.
 	 * We do not just mmap the string table, as it probably
 	 * does not start at a page boundary - we save ourselves a
 	 * lot of nastiness by mmapping the whole file.
@@ -227,14 +227,14 @@ __elf_is_okay__(ehdr)
 	 * We need to check magic, class size, endianess,
 	 * and version before we look at the rest of the
 	 * Elf_Ehdr structure.  These few elements are
-	 * represented in a machine independant fashion.
+	 * represented in a machine independent fashion.
 	 */
 	if (IS_ELF(*ehdr) &&
 	    ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS &&
 	    ehdr->e_ident[EI_DATA] == ELF_TARG_DATA &&
 	    ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) {
 
-		/* Now check the machine dependant header */
+		/* Now check the machine dependent header */
 		if (ehdr->e_machine == ELF_TARG_MACH &&
 		    ehdr->e_version == ELF_TARG_VER)
 			retval = 1;
diff --git a/src/pidfile.c b/src/pidfile.c
index e93d323..4e46367 100644
--- a/src/pidfile.c
+++ b/src/pidfile.c
@@ -109,7 +109,7 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
 
 	/*
 	 * Open the PID file and obtain exclusive lock.
-	 * We truncate PID file here only to remove old PID immediatelly,
+	 * We truncate PID file here only to remove old PID immediately,
 	 * PID file will be truncated again in pidfile_write(), so
 	 * pidfile_write() can be called multiple times.
 	 */


More information about the libbsd mailing list