libbsd: Branch 'master' - 22 commits

Guillem Jover guillem at kemper.freedesktop.org
Mon Jan 11 06:16:19 PST 2010


 Makefile                   |   56 ++++---
 Versions                   |   16 +-
 get-version                |   48 ++++++
 include/bsd/bsd.h          |    3 
 include/bsd/inet.h         |    7 
 include/bsd/random.h       |    9 -
 include/bsd/stdio.h        |   40 +++++
 include/bsd/stdlib.h       |   17 +-
 include/bsd/string.h       |    8 -
 include/bsd/sys/cdefs.h    |    4 
 include/bsd/unistd.h       |   44 ++++++
 include/libutil.h          |   14 +
 man/.gitignore             |    2 
 man/arc4random.3           |  107 ---------------
 man/arc4random_addrandom.3 |    1 
 man/arc4random_stir.3      |    1 
 man/fgetln.3               |  124 -----------------
 man/fmtcheck.3             |  110 ---------------
 man/getmode.3              |    1 
 man/humanize_number.3      |  166 -----------------------
 man/mdX.3                  |  223 -------------------------------
 man/nlist.3                |   77 ----------
 man/readpassphrase.3       |  165 -----------------------
 man/setmode.3              |  114 ---------------
 man/strlcat.3              |    1 
 man/strlcpy.3              |  204 ----------------------------
 man/strmode.3              |  144 --------------------
 man/strtonum.3             |  156 ---------------------
 src/.gitignore             |    2 
 src/arc4random.3           |  128 +++++++++++++++++
 src/arc4random.c           |  195 +++++++++++++++++++--------
 src/arc4random_addrandom.3 |    1 
 src/arc4random_buf.3       |    1 
 src/arc4random_stir.3      |    1 
 src/arc4random_uniform.3   |    1 
 src/bsd_getopt.c           |   13 -
 src/dehumanize_number.3    |    1 
 src/err.c                  |   46 +++---
 src/fgetln.3               |  125 +++++++++++++++++
 src/fgetln.c               |    2 
 src/flopen.3               |  102 ++++++++++++++
 src/flopen.c               |  105 ++++++++++++++
 src/fmtcheck.3             |  111 +++++++++++++++
 src/getmode.3              |    1 
 src/humanize_number.3      |  171 +++++++++++++++++++++++
 src/mdX.3                  |  226 +++++++++++++++++++++++++++++++
 src/nlist.3                |   78 ++++++++++
 src/pidfile.3              |  254 +++++++++++++++++++++++++++++++++++
 src/pidfile.c              |  255 +++++++++++++++++++++++++++++++++++
 src/progname.c             |    8 -
 src/readpassphrase.3       |  168 +++++++++++++++++++++++
 src/setmode.3              |  115 ++++++++++++++++
 src/setproctitle.c         |   33 ++++
 src/strlcat.3              |    1 
 src/strlcat.c              |   43 +-----
 src/strlcpy.3              |  191 ++++++++++++++++++++++++++
 src/strlcpy.c              |   52 ++-----
 src/strmode.3              |  145 ++++++++++++++++++++
 src/strtonum.3             |  159 ++++++++++++++++++++++
 src/unvis.3                |  198 +++++++++++++++++++++++++++
 src/unvis.c                |    7 
 src/vis.3                  |  321 +++++++++++++++++++++++++++++++++++++++++++++
 src/vis.c                  |   17 --
 63 files changed, 3314 insertions(+), 1825 deletions(-)

New commits:
commit ddebbd6792e5c7ae53fb96cdc46566fc843adaa5
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 12:04:03 2010 +0100

    Release libbsd 0.2.0

diff --git a/Makefile b/Makefile
index b44afd7..258bb0c 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ VERSION := $(shell ./get-version)
 
 LIB_NAME := libbsd
 LIB_VERSION_MAJOR := 0
-LIB_VERSION_MINOR := 1
-LIB_VERSION_MICRO := 6
+LIB_VERSION_MINOR := 2
+LIB_VERSION_MICRO := 0
 LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
 
 LIB_PKGCONFIG := $(LIB_NAME).pc
commit abe0a4a7e6e0c8d9c7b8bdb55ade9535ec342578
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 11:02:13 2010 +0100

    Reformat code to KNF

diff --git a/src/bsd_getopt.c b/src/bsd_getopt.c
index 1c878ed..a213d9b 100644
--- a/src/bsd_getopt.c
+++ b/src/bsd_getopt.c
@@ -29,13 +29,12 @@
 int optreset = 0;
 
 int
-bsd_getopt (int argc, char **argv, char *shortopts)
+bsd_getopt(int argc, char **argv, char *shortopts)
 {
-  if (optreset == 1)
-    {
-      optreset = 0;
-      optind = 0;
-    }
+	if (optreset == 1) {
+		optreset = 0;
+		optind = 0;
+	}
 
-  return getopt (argc, argv, shortopts);
+	return getopt(argc, argv, shortopts);
 }
diff --git a/src/err.c b/src/err.c
index c7bb416..d33f08e 100644
--- a/src/err.c
+++ b/src/err.c
@@ -29,44 +29,46 @@
 #include <stdarg.h>
 
 void
-warnc (int code, const char *format, ...)
+warnc(int code, const char *format, ...)
 {
-  int tmp = errno;
-  va_list ap;
-  va_start (ap, format);
+	int tmp = errno;
+	va_list ap;
 
-  errno = code;
-  warn (format, ap);
-  errno = tmp;
+	va_start(ap, format);
 
-  va_end (ap);
+	errno = code;
+	warn(format, ap);
+	errno = tmp;
+
+	va_end(ap);
 }
 
 void
-vwarnc (int code, const char *format, va_list ap)
+vwarnc(int code, const char *format, va_list ap)
 {
-  int tmp = errno;
+	int tmp = errno;
 
-  errno = code;
-  vwarn (format, ap);
-  errno = tmp;
+	errno = code;
+	vwarn(format, ap);
+	errno = tmp;
 }
 
 void
-errc (int status, int code, const char *format, ...)
+errc(int status, int code, const char *format, ...)
 {
-  va_list ap;
-  va_start (ap, format);
+	va_list ap;
+
+	va_start(ap, format);
 
-  errno = code;
-  err (status, format, ap);
+	errno = code;
+	err(status, format, ap);
 
-  va_end (ap);
+	va_end(ap);
 }
 
 void
-verrc (int status, int code, const char *format, va_list ap)
+verrc(int status, int code, const char *format, va_list ap)
 {
-  errno = code;
-  verr (status, format, ap);
+	errno = code;
+	verr(status, format, ap);
 }
diff --git a/src/fgetln.c b/src/fgetln.c
index 317880d..9ccc1b9 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -32,7 +32,7 @@
 
 #ifdef __GLIBC__
 char *
-fgetln (FILE *stream, size_t *len)
+fgetln(FILE *stream, size_t *len)
 {
 	static char *line = NULL;
 	static size_t line_len = 0;
diff --git a/src/progname.c b/src/progname.c
index 9415f17..0a47c22 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -33,13 +33,13 @@
 static char *__progname = NULL;
 
 char *
-getprogname ()
+getprogname()
 {
-  return __progname;
+	return __progname;
 }
 
 void
-setprogname (char *new)
+setprogname(char *new)
 {
-  __progname = new;
+	__progname = new;
 }
commit 2872bfa15193c0b45bf7c212879533b96a8cc2fd
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 01:41:27 2010 +0100

    Add vis and unvis man pages
    
    Taken from OpenBSD.

diff --git a/Makefile b/Makefile
index 357d679..b44afd7 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,8 @@ LIB_MANS := \
 	setmode.3 \
 	getmode.3 \
 	strmode.3 \
+	unvis.3 \
+	vis.3 \
 	$(LIB_MANS_GEN)
 LIB_MANS_GEN := $(patsubst %,src/%,$(LIB_MANS_GEN))
 LIB_MANS := $(patsubst %,src/%,$(LIB_MANS))
diff --git a/src/unvis.3 b/src/unvis.3
new file mode 100644
index 0000000..f318ecf
--- /dev/null
+++ b/src/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 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
new file mode 100644
index 0000000..3da6eb1
--- /dev/null
+++ b/src/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 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 e544a41f62b223cb03c417d7b250557dbec58a3f
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 01:37:18 2010 +0100

    Add dehumanize_number man page link

diff --git a/Makefile b/Makefile
index 5e5b5d3..357d679 100644
--- a/Makefile
+++ b/Makefile
@@ -77,6 +77,7 @@ LIB_MANS := \
 	arc4random_buf.3 \
 	arc4random_stir.3 \
 	arc4random_uniform.3 \
+	dehumanize_number.3 \
 	strtonum.3 \
 	strlcpy.3 \
 	strlcat.3 \
diff --git a/src/dehumanize_number.3 b/src/dehumanize_number.3
new file mode 100644
index 0000000..7f5dcf3
--- /dev/null
+++ b/src/dehumanize_number.3
@@ -0,0 +1 @@
+.so man3/humanize_number.3
commit 7b3873bc1e80b9ddb3505b56735c713917b25945
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 01:35:27 2010 +0100

    Update vis and unvis modules from OpenBSD

diff --git a/src/unvis.c b/src/unvis.c
index 188edca..53da64b 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -235,7 +235,7 @@ strunvis(char *dst, const char *src)
 	char *start = dst;
 	int state = 0;
 
-	while ( (c = *src++) ) {
+	while ((c = *src++)) {
 	again:
 		switch (unvis(dst, c, &state, 0)) {
 		case UNVIS_VALID:
@@ -248,6 +248,7 @@ strunvis(char *dst, const char *src)
 		case UNVIS_NOCHAR:
 			break;
 		default:
+			*dst = '\0';
 			return (-1);
 		}
 	}
@@ -304,8 +305,8 @@ strunvisx(char *dst, const char *src, int flag)
 	char c;
 	char *start = dst;
 	int state = 0;
-    
-	while ( (c = *src++) ) {
+
+	while ((c = *src++)) {
 	again:
 		switch (unvis(dst, c, &state, flag)) {
 		case UNVIS_VALID:
diff --git a/src/vis.c b/src/vis.c
index 189fde8..6153a7f 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -50,10 +50,7 @@
  * vis - visually encode characters
  */
 char *
-vis(dst, c, flag, nextc)
-	char *dst;
-	int c, nextc;
-	int flag;
+vis(char *dst, int c, int flag, int nextc)
 {
 	c = (unsigned char)c;
 
@@ -173,10 +170,7 @@ done:
  *	This is useful for encoding a block of data.
  */
 int
-strvis(dst, src, flag)
-	char *dst;
-	const char *src;
-	int flag;
+strvis(char *dst, const char *src, int flag)
 {
 	char c;
 	char *start;
@@ -231,11 +225,8 @@ strnvis(char *dst, const char *src, size_t siz, int flag)
 	return (dst - start);
 }
 
-strvisx(dst, src, len, flag)
-	char *dst;
-	const char *src;
-	size_t len;
-	int flag;
+int
+strvisx(char *dst, const char *src, size_t len, int flag)
 {
 	int c;
 	char *start;
commit 8103fe1486cdb95e4d985194cac79bc5940e82ce
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 01:33:07 2010 +0100

    Update strlcat and strlcpy from OpenBSD

diff --git a/src/strlcat.c b/src/strlcat.c
index 062ba38..21c8afb 100644
--- a/src/strlcat.c
+++ b/src/strlcat.c
@@ -1,37 +1,21 @@
-/*	$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $	*/
+/*	$OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $	*/
 
 /*
  * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
- * 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. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
+ * 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.
  *
- * 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.
+ * 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.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $");
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-
 #include <sys/types.h>
 #include <string.h>
 
@@ -43,10 +27,7 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp
  * If retval >= siz, truncation occurred.
  */
 size_t
-strlcat(dst, src, siz)
-	char *dst;
-	const char *src;
-	size_t siz;
+strlcat(char *dst, const char *src, size_t siz)
 {
 	char *d = dst;
 	const char *s = src;
diff --git a/src/strlcpy.3 b/src/strlcpy.3
index d32c688..74fbafa 100644
--- a/src/strlcpy.3
+++ b/src/strlcpy.3
@@ -1,33 +1,20 @@
-.\" $OpenBSD: strlcpy.3,v 1.5 1999/06/06 15:17:32 aaron Exp $
+.\" $OpenBSD: strlcpy.3,v 1.18 2005/08/06 03:24:19 jaredy Exp $
 .\"
-.\" Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
-.\" All rights reserved.
+.\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller at courtesan.com>
 .\"
-.\" 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.
+.\" 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.
 .\"
-.\" 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.
+.\" 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.
 .\"
-.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/string/strlcpy.3,v 1.13 2004/07/02 23:52:13 ru Exp $
-.\"
-.Dd June 22, 1998
+.Dd $Mdocdate: May 31 2007 $
 .Dt STRLCPY 3
 .Os
 .Sh NAME
@@ -65,7 +52,7 @@ 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 you should include a byte for the NUL in
+Note that a byte for the NUL should be included in
 .Fa size .
 Also note that
 .Fn strlcpy
@@ -109,8 +96,7 @@ The
 .Fn strlcpy
 and
 .Fn strlcat
-functions return the total length of the string they tried to
-create.
+functions return the total length of the string they tried to create.
 For
 .Fn strlcpy
 that means the length of
@@ -122,10 +108,10 @@ that means the initial length of
 plus
 the length of
 .Fa src .
-While this may seem somewhat confusing it was done to make
+While this may seem somewhat confusing, it was done to make
 truncation detection simple.
 .Pp
-Note however, that if
+Note, however, that if
 .Fn strlcat
 traverses
 .Fa size
@@ -169,8 +155,8 @@ if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
 	goto toolong;
 .Ed
 .Pp
-Since we know how many characters we copied the first time, we can
-speed things up a bit by using a copy instead of an append:
+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;
diff --git a/src/strlcpy.c b/src/strlcpy.c
index ceb2849..1719d35 100644
--- a/src/strlcpy.c
+++ b/src/strlcpy.c
@@ -1,37 +1,21 @@
-/*	$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $	*/
+/*	$OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $	*/
 
 /*
  * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
- * 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. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
+ * 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.
  *
- * 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.
+ * 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.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $");
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-
 #include <sys/types.h>
 #include <string.h>
 
@@ -40,21 +24,19 @@ static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
  * will be copied.  Always NUL terminates (unless siz == 0).
  * Returns strlen(src); if retval >= siz, truncation occurred.
  */
-size_t strlcpy(dst, src, siz)
-	char *dst;
-	const char *src;
-	size_t siz;
+size_t
+strlcpy(char *dst, const char *src, size_t siz)
 {
 	char *d = dst;
 	const char *s = src;
 	size_t n = siz;
 
 	/* Copy as many bytes as will fit */
-	if (n != 0 && --n != 0) {
-		do {
-			if ((*d++ = *s++) == 0)
+	if (n != 0) {
+		while (--n != 0) {
+			if ((*d++ = *s++) == '\0')
 				break;
-		} while (--n != 0);
+		}
 	}
 
 	/* Not enough room in dst, add NUL and traverse rest of src */
commit d63e081303521c45baeaabd002c706196c51048e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 00:57:07 2010 +0100

    Add arc4random_buf and arc4random_uniform functions
    
    Update arc4random module from FreeBSD.

diff --git a/Makefile b/Makefile
index 830037c..5e5b5d3 100644
--- a/Makefile
+++ b/Makefile
@@ -74,7 +74,9 @@ LIB_MANS_GEN := \
 LIB_MANS := \
 	arc4random.3 \
 	arc4random_addrandom.3 \
+	arc4random_buf.3 \
 	arc4random_stir.3 \
+	arc4random_uniform.3 \
 	strtonum.3 \
 	strlcpy.3 \
 	strlcat.3 \
diff --git a/Versions b/Versions
index 70bd8cf..471ffe2 100644
--- a/Versions
+++ b/Versions
@@ -60,5 +60,8 @@ LIBBSD_0.2 {
     pidfile_remove;
 
     setproctitle;
+
+    arc4random_buf;
+    arc4random_uniform;
 } LIBBSD_0.1;
 
diff --git a/src/arc4random.3 b/src/arc4random.3
index 09c24c6..1043602 100644
--- a/src/arc4random.3
+++ b/src/arc4random.3
@@ -28,13 +28,15 @@
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" Manual page, using -mandoc macros
-.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/arc4random.3,v 1.16 2003/07/31 06:18:24 das Exp $
+.\" $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
@@ -46,6 +48,10 @@
 .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"
@@ -69,6 +75,21 @@ and therefore has twice the range of
 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
@@ -79,10 +100,9 @@ and uses it to permute the S-Boxes via
 There is no need to call
 .Fn arc4random_stir
 before using
-.Fn arc4random ,
-since
 .Fn arc4random
-automatically initializes itself.
+functions family, since
+they automatically initialize themselves.
 .Sh EXAMPLES
 The following produces a drop-in replacement for the traditional
 .Fn rand
diff --git a/src/arc4random.c b/src/arc4random.c
index 5c1837e..20fce09 100644
--- a/src/arc4random.c
+++ b/src/arc4random.c
@@ -1,14 +1,23 @@
 /*
- * Arc4 random number generator for OpenBSD.
- * Copyright 1996 David Mazieres <dm at lcs.mit.edu>.
+ * Copyright (c) 1996, David Mazieres <dm at uun.org>
+ * Copyright (c) 2008, Damien Miller <djm at openbsd.org>
+ *
+ * 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.
  *
- * Modification and redistribution in source and binary forms is
- * permitted provided that due credit is given to the author and the
- * OpenBSD project (for instance by leaving this copyright notice
- * intact).
+ * 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.
  */
 
 /*
+ * Arc4 random number generator for OpenBSD.
+ *
  * This code is derived from section 17.1 of Applied Cryptography,
  * second edition, which describes a stream cipher allegedly
  * compatible with RSA Labs "RC4" cipher (the actual description of
@@ -24,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/arc4random.c,v 1.10 2004/03/24 14:44:57 green Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/time.h>
@@ -40,6 +49,8 @@ struct arc4_stream {
 };
 
 #define	RANDOMDEV	"/dev/urandom"
+#define KEYSIZE		128
+
 #ifdef __REENTRANT
 static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
 #define	THREAD_LOCK()	pthread_mutex_lock(&arc4random_mtx)
@@ -52,58 +63,63 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
 static struct arc4_stream rs;
 static int rs_initialized;
 static int rs_stired;
+static int arc4_count;
 
-static inline u_int8_t arc4_getbyte(struct arc4_stream *);
-static void arc4_stir(struct arc4_stream *);
+static inline u_int8_t arc4_getbyte(void);
+static void arc4_stir(void);
 
 static inline void
-arc4_init(struct arc4_stream *as)
+arc4_init(void)
 {
 	int     n;
 
 	for (n = 0; n < 256; n++)
-		as->s[n] = n;
-	as->i = 0;
-	as->j = 0;
+		rs.s[n] = n;
+	rs.i = 0;
+	rs.j = 0;
 }
 
 static inline void
-arc4_addrandom(struct arc4_stream *as, u_char *dat, int datlen)
+arc4_addrandom(u_char *dat, int datlen)
 {
 	int     n;
 	u_int8_t si;
 
-	as->i--;
+	rs.i--;
 	for (n = 0; n < 256; n++) {
-		as->i = (as->i + 1);
-		si = as->s[as->i];
-		as->j = (as->j + si + dat[n % datlen]);
-		as->s[as->i] = as->s[as->j];
-		as->s[as->j] = si;
+		rs.i = (rs.i + 1);
+		si = rs.s[rs.i];
+		rs.j = (rs.j + si + dat[n % datlen]);
+		rs.s[rs.i] = rs.s[rs.j];
+		rs.s[rs.j] = si;
 	}
+	rs.j = rs.i;
 }
 
 static void
-arc4_stir(struct arc4_stream *as)
+arc4_stir(void)
 {
-	int     fd, n;
+	int done, fd, n;
 	struct {
-		struct timeval tv;
-		pid_t pid;
-		u_int8_t rnd[128 - sizeof(struct timeval) - sizeof(pid_t)];
-	}       rdat;
+		struct timeval	tv;
+		pid_t 		pid;
+		u_int8_t 	rnd[KEYSIZE];
+	} rdat;
 
-	gettimeofday(&rdat.tv, NULL);
-	rdat.pid = getpid();
 	fd = open(RANDOMDEV, O_RDONLY, 0);
+	done = 0;
 	if (fd >= 0) {
-		(void) read(fd, rdat.rnd, sizeof(rdat.rnd));
-		close(fd);
+		if (read(fd, &rdat, KEYSIZE) == KEYSIZE)
+			done = 1;
+		(void)close(fd);
 	} 
-	/* fd < 0?  Ah, what the heck. We'll just take whatever was on the
-	 * stack... */
+	if (!done) {
+		(void)gettimeofday(&rdat.tv, NULL);
+		rdat.pid = getpid();
+		/* We'll just take whatever was on the stack too... */
+	}
 
-	arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
+	arc4_addrandom((u_char *)&rdat, KEYSIZE);
 
 	/*
 	 * Throw away the first N bytes of output, as suggested in the
@@ -113,33 +129,34 @@ arc4_stir(struct arc4_stream *as)
 	 * by Ilya Mironov.
 	 */
 	for (n = 0; n < 1024; n++)
-		arc4_getbyte(as);
+		(void) arc4_getbyte();
+	arc4_count = 1600000;
 }
 
 static inline u_int8_t
-arc4_getbyte(struct arc4_stream *as)
+arc4_getbyte(void)
 {
 	u_int8_t si, sj;
 
-	as->i = (as->i + 1);
-	si = as->s[as->i];
-	as->j = (as->j + si);
-	sj = as->s[as->j];
-	as->s[as->i] = sj;
-	as->s[as->j] = si;
+	rs.i = (rs.i + 1);
+	si = rs.s[rs.i];
+	rs.j = (rs.j + si);
+	sj = rs.s[rs.j];
+	rs.s[rs.i] = sj;
+	rs.s[rs.j] = si;
 
-	return (as->s[(si + sj) & 0xff]);
+	return (rs.s[(si + sj) & 0xff]);
 }
 
 static inline u_int32_t
-arc4_getword(struct arc4_stream *as)
+arc4_getword(void)
 {
 	u_int32_t val;
 
-	val = arc4_getbyte(as) << 24;
-	val |= arc4_getbyte(as) << 16;
-	val |= arc4_getbyte(as) << 8;
-	val |= arc4_getbyte(as);
+	val = arc4_getbyte() << 24;
+	val |= arc4_getbyte() << 16;
+	val |= arc4_getbyte() << 8;
+	val |= arc4_getbyte();
 
 	return (val);
 }
@@ -148,55 +165,115 @@ static void
 arc4_check_init(void)
 {
 	if (!rs_initialized) {
-		arc4_init(&rs);
+		arc4_init();
 		rs_initialized = 1;
 	}
 }
 
-static void
+static inline void
 arc4_check_stir(void)
 {
-	if (!rs_stired) {
-		arc4_stir(&rs);
+	if (!rs_stired || arc4_count <= 0) {
+		arc4_stir();
 		rs_stired = 1;
 	}
 }
 
 void
-arc4random_stir()
+arc4random_stir(void)
 {
 	THREAD_LOCK();
 	arc4_check_init();
-	arc4_stir(&rs);
+	arc4_stir();
+	rs_stired = 1;
 	THREAD_UNLOCK();
 }
 
 void
-arc4random_addrandom(dat, datlen)
-	u_char *dat;
-	int     datlen;
+arc4random_addrandom(u_char *dat, int datlen)
 {
 	THREAD_LOCK();
 	arc4_check_init();
 	arc4_check_stir();
-	arc4_addrandom(&rs, dat, datlen);
+	arc4_addrandom(dat, datlen);
 	THREAD_UNLOCK();
 }
 
 u_int32_t
-arc4random()
+arc4random(void)
 {
 	u_int32_t rnd;
 
 	THREAD_LOCK();
 	arc4_check_init();
 	arc4_check_stir();
-	rnd = arc4_getword(&rs);
+	rnd = arc4_getword();
+	arc4_count -= 4;
 	THREAD_UNLOCK();
 
 	return (rnd);
 }
 
+void
+arc4random_buf(void *_buf, size_t n)
+{
+	u_char *buf = (u_char *)_buf;
+
+	THREAD_LOCK();
+	arc4_check_init();
+	while (n--) {
+		arc4_check_stir();
+		buf[n] = arc4_getbyte();
+		arc4_count--;
+	}
+	THREAD_UNLOCK();
+}
+
+/*
+ * Calculate a uniformly distributed random number less than upper_bound
+ * avoiding "modulo bias".
+ *
+ * Uniformity is achieved by generating new random numbers until the one
+ * returned is outside the range [0, 2**32 % upper_bound).  This
+ * guarantees the selected random number will be inside
+ * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
+ * after reduction modulo upper_bound.
+ */
+u_int32_t
+arc4random_uniform(u_int32_t upper_bound)
+{
+	u_int32_t r, min;
+
+	if (upper_bound < 2)
+		return (0);
+
+#if (ULONG_MAX > 0xffffffffUL)
+	min = 0x100000000UL % upper_bound;
+#else
+	/* Calculate (2**32 % upper_bound) avoiding 64-bit math */
+	if (upper_bound > 0x80000000)
+		min = 1 + ~upper_bound;		/* 2**32 - upper_bound */
+	else {
+		/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
+		min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
+	}
+#endif
+
+	/*
+	 * This could theoretically loop forever but each retry has
+	 * p > 0.5 (worst case, usually far better) of selecting a
+	 * number inside the range we need, so it should rarely need
+	 * to re-roll.
+	 */
+	for (;;) {
+		r = arc4random();
+		if (r >= min)
+			break;
+	}
+
+	return (r % upper_bound);
+}
+
 #if 0
 /*-------- Test code for i386 --------*/
 #include <stdio.h>
diff --git a/src/arc4random_buf.3 b/src/arc4random_buf.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/src/arc4random_buf.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/src/arc4random_uniform.3 b/src/arc4random_uniform.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/src/arc4random_uniform.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
commit 3fed78e5b08f78256e533788b4bcd6502b0949d7
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 00:37:03 2010 +0100

    Replace setproctitle dummy macro with a function stub
    
    This way we can replace it later on with a real implementation so that
    applications can immediately benefit from it w/o the need to recompile
    them.

diff --git a/Makefile b/Makefile
index 2fea0b4..830037c 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,7 @@ LIB_SRCS := \
 	pidfile.c \
 	readpassphrase.c \
 	setmode.c \
+	setproctitle.c \
 	strmode.c \
 	strtonum.c \
 	strlcat.c strlcpy.c \
diff --git a/Versions b/Versions
index 631cd5d..70bd8cf 100644
--- a/Versions
+++ b/Versions
@@ -58,5 +58,7 @@ LIBBSD_0.2 {
     pidfile_write;
     pidfile_close;
     pidfile_remove;
+
+    setproctitle;
 } LIBBSD_0.1;
 
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index a0b7860..4d9aa49 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -29,10 +29,6 @@
 
 #include <sys/cdefs.h>
 
-#ifndef setproctitle
-# define setproctitle(fmt, args...)
-#endif
-
 #ifndef __dead2
 # define __dead2
 #endif
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index 16855ec..f9f7874 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -37,6 +37,8 @@
 __BEGIN_DECLS
 mode_t getmode(const void *set, mode_t mode);
 void *setmode(const char *mode_str);
+
+void setproctitle(const char *fmt, ...);
 __END_DECLS
 
 #endif
diff --git a/src/setproctitle.c b/src/setproctitle.c
new file mode 100644
index 0000000..44768b2
--- /dev/null
+++ b/src/setproctitle.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2010 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.
+ */
+
+void
+setproctitle(const char *fmt, ...)
+{
+	/* Stub so that we can implement it later on and programs will
+	 * automatically benefit from it, w/o needing to recompile. */
+}
+
commit 2a81893cc028b40f7832bf033821a1aacfaaea68
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jan 10 00:10:21 2010 +0100

    Add pidfile functions
    
    Taken from FreeBSD.
    
    Remove MAXPATHLEN from ‘struct pidfh’ and allocate pf_path dynamically,
    as some systems do not have such limits. Use dev_t instead of __dev_t.
    Replace EDOOFUS with EINVAL.

diff --git a/Makefile b/Makefile
index be8314b..2fea0b4 100644
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,7 @@ LIB_SRCS := \
 	dehumanize_number.c \
 	inet_net_pton.c \
 	hash/md5.c \
+	pidfile.c \
 	readpassphrase.c \
 	setmode.c \
 	strmode.c \
@@ -82,6 +83,7 @@ LIB_MANS := \
 	humanize_number.3 \
 	fmtcheck.3 \
 	nlist.3 \
+	pidfile.3 \
 	setmode.3 \
 	getmode.3 \
 	strmode.3 \
diff --git a/Versions b/Versions
index 7b092da..631cd5d 100644
--- a/Versions
+++ b/Versions
@@ -53,5 +53,10 @@ LIBBSD_0.2 {
     readpassphrase;
 
     flopen;
+
+    pidfile_open;
+    pidfile_write;
+    pidfile_close;
+    pidfile_remove;
 } LIBBSD_0.1;
 
diff --git a/include/libutil.h b/include/libutil.h
index 298bbc3..21a22cd 100644
--- a/include/libutil.h
+++ b/include/libutil.h
@@ -42,12 +42,24 @@
 #include <features.h>
 #include <sys/types.h>
 
+/* for pidfile.c */
+struct pidfh {
+	int	pf_fd;
+	char	*pf_path;
+	dev_t	pf_dev;
+	ino_t	pf_ino;
+};
 
 __BEGIN_DECLS
 int humanize_number(char *buf, size_t len, int64_t bytes,
     const char *suffix, int scale, int flags);
 
 int flopen(const char *_path, int _flags, ...);
+
+struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr);
+int pidfile_write(struct pidfh *pfh);
+int pidfile_close(struct pidfh *pfh);
+int pidfile_remove(struct pidfh *pfh);
 __END_DECLS
 
 /* humanize_number(3) */
diff --git a/src/pidfile.3 b/src/pidfile.3
new file mode 100644
index 0000000..34214c0
--- /dev/null
+++ b/src/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 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/pidfile.c b/src/pidfile.c
new file mode 100644
index 0000000..e93d323
--- /dev/null
+++ b/src/pidfile.c
@@ -0,0 +1,255 @@
+/*-
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <time.h>
+#include <err.h>
+#include <errno.h>
+#include <libutil.h>
+
+static int _pidfile_remove(struct pidfh *pfh, int freeit);
+
+static int
+pidfile_verify(struct pidfh *pfh)
+{
+	struct stat sb;
+
+	if (pfh == NULL || pfh->pf_fd == -1)
+		return (EINVAL);
+	/*
+	 * Check remembered descriptor.
+	 */
+	if (fstat(pfh->pf_fd, &sb) == -1)
+		return (errno);
+	if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino)
+		return (EINVAL);
+	return (0);
+}
+
+static int
+pidfile_read(const char *path, pid_t *pidptr)
+{
+	char buf[16], *endptr;
+	int error, fd, i;
+
+	fd = open(path, O_RDONLY);
+	if (fd == -1)
+		return (errno);
+
+	i = read(fd, buf, sizeof(buf) - 1);
+	error = errno;	/* Remember errno in case close() wants to change it. */
+	close(fd);
+	if (i == -1)
+		return (error);
+	else if (i == 0)
+		return (EAGAIN);
+	buf[i] = '\0';
+
+	*pidptr = strtol(buf, &endptr, 10);
+	if (endptr != &buf[i])
+		return (EINVAL);
+
+	return (0);
+}
+
+struct pidfh *
+pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
+{
+	struct pidfh *pfh;
+	struct stat sb;
+	int error, fd, len, count;
+	struct timespec rqtp;
+
+	pfh = malloc(sizeof(*pfh));
+	if (pfh == NULL)
+		return (NULL);
+
+	if (path == NULL) {
+		len = asprintf(&pfh->pf_path, "/var/run/%s.pid", getprogname());
+		if (len < 0) {
+			free(pfh);
+			return (NULL);
+		}
+	} else
+		pfh->pf_path = strdup(path);
+
+	/*
+	 * Open the PID file and obtain exclusive lock.
+	 * We truncate PID file here only to remove old PID immediatelly,
+	 * PID file will be truncated again in pidfile_write(), so
+	 * pidfile_write() can be called multiple times.
+	 */
+	fd = flopen(pfh->pf_path,
+	    O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
+	if (fd == -1) {
+		count = 0;
+		rqtp.tv_sec = 0;
+		rqtp.tv_nsec = 5000000;
+		if (errno == EWOULDBLOCK && pidptr != NULL) {
+		again:
+			errno = pidfile_read(pfh->pf_path, pidptr);
+			if (errno == 0)
+				errno = EEXIST;
+			else if (errno == EAGAIN) {
+				if (++count <= 3) {
+					nanosleep(&rqtp, 0);
+					goto again;
+				}
+			}
+		}
+		free(pfh->pf_path);
+		free(pfh);
+		return (NULL);
+	}
+	/*
+	 * Remember file information, so in pidfile_write() we are sure we write
+	 * to the proper descriptor.
+	 */
+	if (fstat(fd, &sb) == -1) {
+		error = errno;
+		unlink(pfh->pf_path);
+		free(pfh->pf_path);
+		close(fd);
+		free(pfh);
+		errno = error;
+		return (NULL);
+	}
+
+	pfh->pf_fd = fd;
+	pfh->pf_dev = sb.st_dev;
+	pfh->pf_ino = sb.st_ino;
+
+	return (pfh);
+}
+
+int
+pidfile_write(struct pidfh *pfh)
+{
+	char pidstr[16];
+	int error, fd;
+
+	/*
+	 * Check remembered descriptor, so we don't overwrite some other
+	 * file if pidfile was closed and descriptor reused.
+	 */
+	errno = pidfile_verify(pfh);
+	if (errno != 0) {
+		/*
+		 * Don't close descriptor, because we are not sure if it's ours.
+		 */
+		return (-1);
+	}
+	fd = pfh->pf_fd;
+
+	/*
+	 * Truncate PID file, so multiple calls of pidfile_write() are allowed.
+	 */
+	if (ftruncate(fd, 0) == -1) {
+		error = errno;
+		_pidfile_remove(pfh, 0);
+		errno = error;
+		return (-1);
+	}
+
+	snprintf(pidstr, sizeof(pidstr), "%u", getpid());
+	if (pwrite(fd, pidstr, strlen(pidstr), 0) != (ssize_t)strlen(pidstr)) {
+		error = errno;
+		_pidfile_remove(pfh, 0);
+		errno = error;
+		return (-1);
+	}
+
+	return (0);
+}
+
+int
+pidfile_close(struct pidfh *pfh)
+{
+	int error;
+
+	error = pidfile_verify(pfh);
+	if (error != 0) {
+		errno = error;
+		return (-1);
+	}
+
+	if (close(pfh->pf_fd) == -1)
+		error = errno;
+	free(pfh->pf_path);
+	free(pfh);
+	if (error != 0) {
+		errno = error;
+		return (-1);
+	}
+	return (0);
+}
+
+static int
+_pidfile_remove(struct pidfh *pfh, int freeit)
+{
+	int error;
+
+	error = pidfile_verify(pfh);
+	if (error != 0) {
+		errno = error;
+		return (-1);
+	}
+
+	if (unlink(pfh->pf_path) == -1)
+		error = errno;
+	if (close(pfh->pf_fd) == -1) {
+		if (error == 0)
+			error = errno;
+	}
+	if (freeit) {
+		free(pfh->pf_path);
+		free(pfh);
+	} else
+		pfh->pf_fd = -1;
+	if (error != 0) {
+		errno = error;
+		return (-1);
+	}
+	return (0);
+}
+
+int
+pidfile_remove(struct pidfh *pfh)
+{
+
+	return (_pidfile_remove(pfh, 1));
+}
commit 98a2479f0ba02a0c54ff360aa5745ff5a6939b2e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jan 9 23:49:32 2010 +0100

    Add flopen function
    
    Taken from FreeBSD.

diff --git a/Makefile b/Makefile
index 2d51ba1..be8314b 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ LIB_SRCS := \
 	bsd_getopt.c \
 	err.c \
 	fgetln.c \
+	flopen.c \
 	heapsort.c \
 	humanize_number.c \
 	dehumanize_number.c \
@@ -76,6 +77,7 @@ LIB_MANS := \
 	strlcpy.3 \
 	strlcat.3 \
 	fgetln.3 \
+	flopen.3 \
 	readpassphrase.3 \
 	humanize_number.3 \
 	fmtcheck.3 \
diff --git a/Versions b/Versions
index 24548ca..7b092da 100644
--- a/Versions
+++ b/Versions
@@ -51,5 +51,7 @@ LIBBSD_0.2 {
     dehumanize_number;
 
     readpassphrase;
+
+    flopen;
 } LIBBSD_0.1;
 
diff --git a/include/libutil.h b/include/libutil.h
index 5f72f8c..298bbc3 100644
--- a/include/libutil.h
+++ b/include/libutil.h
@@ -46,6 +46,8 @@
 __BEGIN_DECLS
 int humanize_number(char *buf, size_t len, int64_t bytes,
     const char *suffix, int scale, int flags);
+
+int flopen(const char *_path, int _flags, ...);
 __END_DECLS
 
 /* humanize_number(3) */
diff --git a/src/flopen.3 b/src/flopen.3
new file mode 100644
index 0000000..4c53d46
--- /dev/null
+++ b/src/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 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/flopen.c b/src/flopen.c
new file mode 100644
index 0000000..754c9c0
--- /dev/null
+++ b/src/flopen.c
@@ -0,0 +1,105 @@
+/*-
+ * 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
+ *    in this position and unchanged.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/file.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#include <libutil.h>
+
+int
+flopen(const char *path, int flags, ...)
+{
+	int fd, operation, serrno, trunc;
+	struct stat sb, fsb;
+	mode_t mode;
+
+#ifdef O_EXLOCK
+	flags &= ~O_EXLOCK;
+#endif
+
+	mode = 0;
+	if (flags & O_CREAT) {
+		va_list ap;
+
+		va_start(ap, flags);
+		mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
+		va_end(ap);
+	}
+
+        operation = LOCK_EX;
+        if (flags & O_NONBLOCK)
+                operation |= LOCK_NB;
+
+	trunc = (flags & O_TRUNC);
+	flags &= ~O_TRUNC;
+
+	for (;;) {
+		if ((fd = open(path, flags, mode)) == -1)
+			/* non-existent or no access */
+			return (-1);
+		if (flock(fd, operation) == -1) {
+			/* unsupported or interrupted */
+			serrno = errno;
+			(void)close(fd);
+			errno = serrno;
+			return (-1);
+		}
+		if (stat(path, &sb) == -1) {
+			/* disappeared from under our feet */
+			(void)close(fd);
+			continue;
+		}
+		if (fstat(fd, &fsb) == -1) {
+			/* can't happen [tm] */
+			serrno = errno;
+			(void)close(fd);
+			errno = serrno;
+			return (-1);
+		}
+		if (sb.st_dev != fsb.st_dev ||
+		    sb.st_ino != fsb.st_ino) {
+			/* changed under our feet */
+			(void)close(fd);
+			continue;
+		}
+		if (trunc && ftruncate(fd, 0) != 0) {
+			/* can't happen [tm] */
+			serrno = errno;
+			(void)close(fd);
+			errno = serrno;
+			return (-1);
+		}
+		return (fd);
+	}
+}
commit 57cc5326cf75826c5d3b415673e2574384d12850
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jan 9 20:17:16 2010 +0100

    Move man pages to the same directory as the source code
    
    This matches BSD style source tree, and makes it easier to see what's
    missing.

diff --git a/Makefile b/Makefile
index 7f165e7..2d51ba1 100644
--- a/Makefile
+++ b/Makefile
@@ -84,8 +84,8 @@ LIB_MANS := \
 	getmode.3 \
 	strmode.3 \
 	$(LIB_MANS_GEN)
-LIB_MANS_GEN := $(patsubst %,man/%,$(LIB_MANS_GEN))
-LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
+LIB_MANS_GEN := $(patsubst %,src/%,$(LIB_MANS_GEN))
+LIB_MANS := $(patsubst %,src/%,$(LIB_MANS))
 
 LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o)
 LIB_SHARED_OBJS := $(LIB_SRCS:%.c=%.lo)
@@ -115,7 +115,7 @@ man: $(LIB_MANS)
 %.o: %.c
 	$(CC) -o $@ $(MK_CFLAGS) $(CFLAGS) -c $<
 
-man/md5.3bsd:  man/mdX.3
+src/md5.3bsd:  src/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
deleted file mode 100644
index ed4f453..0000000
--- a/man/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-md5.3
-md5.3bsd
diff --git a/man/arc4random.3 b/man/arc4random.3
deleted file mode 100644
index 09c24c6..0000000
--- a/man/arc4random.3
+++ /dev/null
@@ -1,108 +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: /repoman/r/ncvs/src/lib/libc/gen/arc4random.3,v 1.16 2003/07/31 06:18:24 das Exp $
-.\"
-.Dd April 15, 1997
-.Dt ARC4RANDOM 3
-.Os
-.Sh NAME
-.Nm arc4random ,
-.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 stdlib.h
-.Ft u_int32_t
-.Fn arc4random "void"
-.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
-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 ,
-since
-.Fn arc4random
-automatically initializes itself.
-.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
deleted file mode 100644
index 74a34ce..0000000
--- a/man/arc4random_addrandom.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/arc4random.3
diff --git a/man/arc4random_stir.3 b/man/arc4random_stir.3
deleted file mode 100644
index 74a34ce..0000000
--- a/man/arc4random_stir.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/arc4random.3
diff --git a/man/fgetln.3 b/man/fgetln.3
deleted file mode 100644
index cc33a0a..0000000
--- a/man/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 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/fmtcheck.3 b/man/fmtcheck.3
deleted file mode 100644
index 86a3563..0000000
--- a/man/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 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
deleted file mode 100644
index 63315e7..0000000
--- a/man/getmode.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/setmode.3
diff --git a/man/humanize_number.3 b/man/humanize_number.3
deleted file mode 100644
index 403e173..0000000
--- a/man/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 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
deleted file mode 100644
index 963d221..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 <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/nlist.3 b/man/nlist.3
deleted file mode 100644
index 3ee5404..0000000
--- a/man/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 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/readpassphrase.3 b/man/readpassphrase.3
deleted file mode 100644
index c9d55a2..0000000
--- a/man/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 <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/setmode.3 b/man/setmode.3
deleted file mode 100644
index c0a2837..0000000
--- a/man/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 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/strlcat.3 b/man/strlcat.3
deleted file mode 100644
index d968886..0000000
--- a/man/strlcat.3
+++ /dev/null
@@ -1 +0,0 @@
-.so man3/strlcpy.3
diff --git a/man/strlcpy.3 b/man/strlcpy.3
deleted file mode 100644
index d32c688..0000000
--- a/man/strlcpy.3
+++ /dev/null
@@ -1,205 +0,0 @@
-.\" $OpenBSD: strlcpy.3,v 1.5 1999/06/06 15:17:32 aaron Exp $
-.\"
-.\" Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
-.\" 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. 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.
-.\"
-.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/string/strlcpy.3,v 1.13 2004/07/02 23:52:13 ru Exp $
-.\"
-.Dd June 22, 1998
-.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 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 you should include a byte for the NUL 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 we know how many characters we copied the first time, we can
-speed things 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
deleted file mode 100644
index b2dfaf4..0000000
--- a/man/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 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
deleted file mode 100644
index c5f3111..0000000
--- a/man/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 stdlib.h
-.In limits.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/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..ed4f453
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,2 @@
+md5.3
+md5.3bsd
diff --git a/src/arc4random.3 b/src/arc4random.3
new file mode 100644
index 0000000..09c24c6
--- /dev/null
+++ b/src/arc4random.3
@@ -0,0 +1,108 @@
+.\" $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: /repoman/r/ncvs/src/lib/libc/gen/arc4random.3,v 1.16 2003/07/31 06:18:24 das Exp $
+.\"
+.Dd April 15, 1997
+.Dt ARC4RANDOM 3
+.Os
+.Sh NAME
+.Nm arc4random ,
+.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 stdlib.h
+.Ft u_int32_t
+.Fn arc4random "void"
+.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
+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 ,
+since
+.Fn arc4random
+automatically initializes itself.
+.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
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/src/arc4random_addrandom.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/src/arc4random_stir.3 b/src/arc4random_stir.3
new file mode 100644
index 0000000..74a34ce
--- /dev/null
+++ b/src/arc4random_stir.3
@@ -0,0 +1 @@
+.so man3/arc4random.3
diff --git a/src/fgetln.3 b/src/fgetln.3
new file mode 100644
index 0000000..cc33a0a
--- /dev/null
+++ b/src/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 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/fmtcheck.3 b/src/fmtcheck.3
new file mode 100644
index 0000000..86a3563
--- /dev/null
+++ b/src/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 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
new file mode 100644
index 0000000..63315e7
--- /dev/null
+++ b/src/getmode.3
@@ -0,0 +1 @@
+.so man3/setmode.3
diff --git a/src/humanize_number.3 b/src/humanize_number.3
new file mode 100644
index 0000000..403e173
--- /dev/null
+++ b/src/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 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
new file mode 100644
index 0000000..963d221
--- /dev/null
+++ b/src/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 <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/nlist.3 b/src/nlist.3
new file mode 100644
index 0000000..3ee5404
--- /dev/null
+++ b/src/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 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/readpassphrase.3 b/src/readpassphrase.3
new file mode 100644
index 0000000..c9d55a2
--- /dev/null
+++ b/src/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 <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/setmode.3 b/src/setmode.3
new file mode 100644
index 0000000..c0a2837
--- /dev/null
+++ b/src/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 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/strlcat.3 b/src/strlcat.3
new file mode 100644
index 0000000..d968886
--- /dev/null
+++ b/src/strlcat.3
@@ -0,0 +1 @@
+.so man3/strlcpy.3
diff --git a/src/strlcpy.3 b/src/strlcpy.3
new file mode 100644
index 0000000..d32c688
--- /dev/null
+++ b/src/strlcpy.3
@@ -0,0 +1,205 @@
+.\" $OpenBSD: strlcpy.3,v 1.5 1999/06/06 15:17:32 aaron Exp $
+.\"
+.\" Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
+.\" 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. 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.
+.\"
+.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/string/strlcpy.3,v 1.13 2004/07/02 23:52:13 ru Exp $
+.\"
+.Dd June 22, 1998
+.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 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 you should include a byte for the NUL 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 we know how many characters we copied the first time, we can
+speed things 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
new file mode 100644
index 0000000..b2dfaf4
--- /dev/null
+++ b/src/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 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
new file mode 100644
index 0000000..c5f3111
--- /dev/null
+++ b/src/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 stdlib.h
+.In limits.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 .
commit 9e4adc4633b321bf4f3f41feeac7597162cf88f9
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Dec 13 01:52:03 2009 +0100

    build: Untangle the package version from the soversion
    
    Add a new script to generate the package version from git. Use that for
    the pkg-config file and the tarball name.

diff --git a/Makefile b/Makefile
index 282fa7c..7f165e7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+VERSION := $(shell ./get-version)
+
 LIB_NAME := libbsd
 LIB_VERSION_MAJOR := 0
 LIB_VERSION_MINOR := 1
@@ -10,7 +12,7 @@ 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)-$(LIB_VERSION)
+TAR_NAME := $(LIB_NAME)-$(VERSION)
 TAR_FILE := $(TAR_NAME).tar.gz
 
 LIB_DIST := \
@@ -120,7 +122,7 @@ src/hash/md5hl.c: src/hash/helper.c
 	sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
 
 $(LIB_PKGCONFIG): $(LIB_PKGCONFIG).in
-	sed -e 's:@VERSION@:$(LIB_VERSION):' \
+	sed -e 's:@VERSION@:$(VERSION):' \
 	    -e 's:@prefix@:$(value prefix):' \
 	    -e 's:@exec_prefix@:$(value exec_prefix):' \
 	    -e 's:@libdir@:$(value usrlibdir):' \
@@ -149,6 +151,7 @@ ChangeLog:
 .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)
diff --git a/get-version b/get-version
new file mode 100755
index 0000000..5608445
--- /dev/null
+++ b/get-version
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# get-version
+#
+# 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
+# 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.
+
+if [ -f .dist-version ]; then
+  # Get the version from the file distributed in the tarball.
+  version=$(cat .dist-version)
+elif [ -d .git ]; then
+  # Ger the version from the git repository.
+  version=$(git describe --abbrev=4 HEAD 2>/dev/null)
+
+  # Check if we are on a dirty checkout.
+  git update-index --refresh -q >/dev/null
+  dirty=$(git diff-index --name-only HEAD 2>/dev/null)
+  if [ -n "$dirty" ]; then
+    version="$version-dirty"
+  fi
+else
+  echo "error: cannot get project version." 1>&2
+  exit 1
+fi
+
+echo "$version"
+
commit db406fe24ce18ddce4aa0c5985a77233347d3f27
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Dec 12 01:46:25 2009 +0100

    build: Make dist use files from git plus few autogenerated ones
    
    To avoid forgetting to include files, we'll use “git ls-files” and will
    include few precious autogenerated files that cannot be generated later
    on w/o git. This includes mainly the ChangeLog.

diff --git a/Makefile b/Makefile
index 190e10d..282fa7c 100644
--- a/Makefile
+++ b/Makefile
@@ -14,11 +14,7 @@ TAR_NAME := $(LIB_NAME)-$(LIB_VERSION)
 TAR_FILE := $(TAR_NAME).tar.gz
 
 LIB_DIST := \
-	Makefile \
-	README \
-	ChangeLog \
-	Versions \
-	$(LIB_PKGCONFIG).in
+	ChangeLog
 
 LIB_SRCS_GEN := \
 	hash/md5hl.c
@@ -151,9 +147,9 @@ ChangeLog:
 	-git log --stat -C >$@
 
 .PHONY: dist
-dist: ChangeLog
+dist: $(LIB_DIST)
 	mkdir $(TAR_NAME)
-	cp -a include src man $(LIB_DIST) $(TAR_NAME)
+	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)
commit 9396cc62cf01f282feef7ef9f212f73691100d04
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jan 9 19:56:45 2010 +0100

    build: Do not duplicate generated filenames in several variables

diff --git a/Makefile b/Makefile
index c751f32..190e10d 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,8 @@ LIB_DIST := \
 	Versions \
 	$(LIB_PKGCONFIG).in
 
+LIB_SRCS_GEN := \
+	hash/md5hl.c
 LIB_SRCS := \
 	arc4random.c \
 	bsd_getopt.c \
@@ -29,7 +31,7 @@ LIB_SRCS := \
 	humanize_number.c \
 	dehumanize_number.c \
 	inet_net_pton.c \
-	hash/md5.c hash/md5hl.c \
+	hash/md5.c \
 	readpassphrase.c \
 	setmode.c \
 	strmode.c \
@@ -38,13 +40,11 @@ LIB_SRCS := \
 	fmtcheck.c \
 	nlist.c \
 	progname.c \
-	vis.c unvis.c
+	vis.c unvis.c \
+	$(LIB_SRCS_GEN)
+LIB_SRCS_GEN := $(patsubst %,src/%,$(LIB_SRCS_GEN))
 LIB_SRCS := $(patsubst %,src/%,$(LIB_SRCS))
 
-LIB_GEN_SRCS := \
-	man/md5.3bsd \
-	src/hash/md5hl.c
-
 LIB_INCLUDES := \
 	bsd/cdefs.h \
 	bsd/queue.h \
@@ -68,6 +68,8 @@ LIB_INCLUDES := \
 	vis.h \
 	libutil.h
 
+LIB_MANS_GEN := \
+	md5.3bsd
 LIB_MANS := \
 	arc4random.3 \
 	arc4random_addrandom.3 \
@@ -83,7 +85,8 @@ LIB_MANS := \
 	setmode.3 \
 	getmode.3 \
 	strmode.3 \
-	md5.3bsd
+	$(LIB_MANS_GEN)
+LIB_MANS_GEN := $(patsubst %,man/%,$(LIB_MANS_GEN))
 LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
 
 LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o)
@@ -183,7 +186,7 @@ endif
 .PHONY: clean
 clean:
 	rm -f $(LIB_PKGCONFIG)
-	rm -f $(LIB_GEN_SRCS)
+	rm -f $(LIB_SRCS_GEN) $(LIB_MANS_GEN)
 	rm -f $(LIB_STATIC_OBJS)
 	rm -f $(LIB_STATIC)
 	rm -f $(LIB_SHARED_OBJS)
commit 7a70f1b019a64902a3c8a722ee5287d72a1cbf5b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:24:31 2009 +0100

    Move fmtcheck and fgetln declarations to <bsd/stdio.h>
    
    This is were they are located on the BSDs.

diff --git a/Makefile b/Makefile
index 91893e7..c751f32 100644
--- a/Makefile
+++ b/Makefile
@@ -60,6 +60,7 @@ LIB_INCLUDES := \
 	bsd/md5.h \
 	bsd/string.h \
 	bsd/bsd.h \
+	bsd/stdio.h \
 	bsd/stdlib.h \
 	bsd/readpassphrase.h \
 	bsd/unistd.h \
diff --git a/include/bsd/stdio.h b/include/bsd/stdio.h
new file mode 100644
index 0000000..882f374
--- /dev/null
+++ b/include/bsd/stdio.h
@@ -0,0 +1,40 @@
+/*
+ * 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_STDIO_H
+#define LIBBSD_STDIO_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+__BEGIN_DECLS
+const char *fmtcheck(const char *, const char *);
+
+char *fgetln(FILE *fp, size_t *lenp);
+__END_DECLS
+
+#endif
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index e2a678a..cec5a28 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -37,7 +37,8 @@
 /* For compatibility with NetBSD, which defines humanize_number here. */
 #include <libutil.h>
 
-/* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
+/* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */
+#include <bsd/stdio.h>
 #include <bsd/unistd.h>
 
 __BEGIN_DECLS
@@ -47,8 +48,6 @@ void arc4random_addrandom(u_char *dat, int datlen);
 
 int dehumanize_number(const char *str, int64_t *size);
 
-const char *fmtcheck (const char *, const char *);
-
 char *getprogname ();
 void setprogname (char *);
 
diff --git a/include/bsd/string.h b/include/bsd/string.h
index 293e093..cf72cc0 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -29,13 +29,13 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
-#include <stddef.h>
-#include <stdio.h>
+
+/* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
+#include <bsd/stdio.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);
-char *fgetln(FILE *fp, size_t *lenp);
 void strmode(mode_t mode, char *str);
 __END_DECLS
 
commit ca28f28046b2cc4beb38cb4b63c75f0ac6379bcd
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:21:14 2009 +0100

    Move setmode and getmode declarations to <bsd/unistd.h>
    
    This is were they are located on the BSDs.

diff --git a/Makefile b/Makefile
index 606242a..91893e7 100644
--- a/Makefile
+++ b/Makefile
@@ -62,6 +62,7 @@ LIB_INCLUDES := \
 	bsd/bsd.h \
 	bsd/stdlib.h \
 	bsd/readpassphrase.h \
+	bsd/unistd.h \
 	nlist.h \
 	vis.h \
 	libutil.h
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 2357334..e2a678a 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -37,6 +37,9 @@
 /* For compatibility with NetBSD, which defines humanize_number here. */
 #include <libutil.h>
 
+/* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
+#include <bsd/unistd.h>
+
 __BEGIN_DECLS
 u_int32_t arc4random();
 void arc4random_stir();
@@ -51,13 +54,6 @@ void setprogname (char *);
 
 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
 
-#ifndef S_ISTXT
-#define S_ISTXT S_ISVTX
-#endif
-
-mode_t getmode(const void *set, mode_t mode);
-void *setmode(const char *mode_str);
-
 long long strtonum(const char *nptr, long long minval, long long maxval,
                    const char **errstr);
 __END_DECLS
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
new file mode 100644
index 0000000..16855ec
--- /dev/null
+++ b/include/bsd/unistd.h
@@ -0,0 +1,42 @@
+/*
+ * 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_UNISTD_H
+#define LIBBSD_UNISTD_H
+
+#include <sys/cdefs.h>
+#include <sys/stat.h>
+
+#ifndef S_ISTXT
+#define S_ISTXT S_ISVTX
+#endif
+
+__BEGIN_DECLS
+mode_t getmode(const void *set, mode_t mode);
+void *setmode(const char *mode_str);
+__END_DECLS
+
+#endif
commit dd2756e000208ee9e4cde3373f217fc7c98f0610
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:13:42 2009 +0100

    Mark inclusion of <time.h> from <bsd/bsd.h> deprecated
    
    This will be removed at some point in the future.

diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h
index 437cccc..8ebb12c 100644
--- a/include/bsd/bsd.h
+++ b/include/bsd/bsd.h
@@ -40,6 +40,8 @@
 #include <bsd/err.h>
 #include <bsd/getopt.h>
 #include <bsd/md5.h>
+
+/* FIXME: Will be removed in the future. */
 #include <time.h>
 
 #endif
commit 3c9182b85e785159b349106c04ccc1b4ec045350
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:12:26 2009 +0100

    Move arc4random declarations to <bsd/stdlib.h>
    
    This is were they are located on the BSDs.

diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h
index 237fe16..437cccc 100644
--- a/include/bsd/bsd.h
+++ b/include/bsd/bsd.h
@@ -39,7 +39,6 @@
 #include <bsd/string.h>
 #include <bsd/err.h>
 #include <bsd/getopt.h>
-#include <bsd/random.h>
 #include <bsd/md5.h>
 #include <time.h>
 
diff --git a/include/bsd/random.h b/include/bsd/random.h
index f76adea..f4ef7d3 100644
--- a/include/bsd/random.h
+++ b/include/bsd/random.h
@@ -27,14 +27,9 @@
 #ifndef LIBBSD_RANDOM_H
 #define LIBBSD_RANDOM_H
 
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#warning "This header is deprecated, use the one in bsd/stdlib.h instead."
 
-__BEGIN_DECLS
-u_int32_t arc4random();
-void arc4random_stir();
-void arc4random_addrandom(u_char *dat, int datlen);
-__END_DECLS
+#include <bsd/stdlib.h>
 
 #endif
 
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 453c33d..2357334 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -38,6 +38,10 @@
 #include <libutil.h>
 
 __BEGIN_DECLS
+u_int32_t arc4random();
+void arc4random_stir();
+void arc4random_addrandom(u_char *dat, int datlen);
+
 int dehumanize_number(const char *str, int64_t *size);
 
 const char *fmtcheck (const char *, const char *);
commit 4d17a18db559a3e3485d049cddf808090f38e8be
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:06:27 2009 +0100

    Deprecate <bsd/inet.h>
    
    The only function declared in that header file was inet_net_pton, which
    is already provided by glibc. Will be removed on the next SONAME bump.

diff --git a/Versions b/Versions
index 3fc25dc..24548ca 100644
--- a/Versions
+++ b/Versions
@@ -9,7 +9,8 @@ LIBBSD_0.0 {
     fmtcheck;
     heapsort;
     humanize_number;
-    inet_net_pton;
+
+    inet_net_pton; /* XXX: Already provided by glibc, remove. */
 
     getprogname; setprogname;
     strlcpy;
diff --git a/include/bsd/inet.h b/include/bsd/inet.h
index 1f6e597..0e98548 100644
--- a/include/bsd/inet.h
+++ b/include/bsd/inet.h
@@ -27,12 +27,9 @@
 #ifndef LIBBSD_INET_H
 #define LIBBSD_INET_H
 
-#include <sys/cdefs.h>
-#include <stddef.h>
+#warning "This header is deprecated, use the one in arpa/inet.h instead."
 
-__BEGIN_DECLS
-int inet_net_pton(int af, const char *src, void *dst, siez_t size);
-__END_DECLS
+#include <arpa/inet.h>
 
 #endif
 
commit 7da57b293f96d0c52e5b76b539e934db49323ee2
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:01:02 2009 +0100

    Remove traces of fgetwln, it was never included
    
    This function was exposed in the header file and the versioning symbol
    file, but the actual code was never here.

diff --git a/Versions b/Versions
index 5cdf9e0..3fc25dc 100644
--- a/Versions
+++ b/Versions
@@ -6,7 +6,6 @@ LIBBSD_0.0 {
     bsd_getopt; optreset;
     errc; warnc; verrc; vwarnc;
     fgetln;
-    fgetwln;
     fmtcheck;
     heapsort;
     humanize_number;
diff --git a/include/bsd/string.h b/include/bsd/string.h
index cf6368b..293e093 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -36,8 +36,6 @@ __BEGIN_DECLS
 size_t strlcpy(char *dst, const char *src, size_t siz);
 size_t strlcat(char *dst, const char *src, size_t siz);
 char *fgetln(FILE *fp, size_t *lenp);
-wchar_t *fgetwln(FILE * __restrict fp, size_t *lenp);
-
 void strmode(mode_t mode, char *str);
 __END_DECLS
 
commit 254808d9ef26c5910f981f8119af62db3d7fd72e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 23:26:44 2009 +0100

    Define NetBSD version 5.0 for .Nx to avoid groff warning
    
    This is a temporary workaround, the proper fix is to get groff to know
    newest BSD versions.

diff --git a/man/humanize_number.3 b/man/humanize_number.3
index fb91d3b..403e173 100644
--- a/man/humanize_number.3
+++ b/man/humanize_number.3
@@ -166,4 +166,6 @@ first appeared in
 .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 .
commit 183cc3cbf1c42eedbde8cf18da52ec0004b9049f
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Dec 11 21:31:48 2009 +0100

    Correct library name in man pages

diff --git a/man/arc4random.3 b/man/arc4random.3
index a6aaf9f..09c24c6 100644
--- a/man/arc4random.3
+++ b/man/arc4random.3
@@ -39,7 +39,8 @@
 .Nm arc4random_addrandom
 .Nd arc4 random number generator
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
 .Ft u_int32_t
diff --git a/man/fgetln.3 b/man/fgetln.3
index c01d1ef..cc33a0a 100644
--- a/man/fgetln.3
+++ b/man/fgetln.3
@@ -35,7 +35,8 @@
 .Nm fgetln
 .Nd get a line from a stream
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
 .Ft char *
diff --git a/man/fmtcheck.3 b/man/fmtcheck.3
index 3b99968..86a3563 100644
--- a/man/fmtcheck.3
+++ b/man/fmtcheck.3
@@ -34,7 +34,8 @@
 .Xr printf 3 Ns -style
 format string
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
 .Ft const char *
diff --git a/man/humanize_number.3 b/man/humanize_number.3
index 90465af..fb91d3b 100644
--- a/man/humanize_number.3
+++ b/man/humanize_number.3
@@ -34,6 +34,9 @@
 .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 stdlib.h
 .Ft int
diff --git a/man/mdX.3 b/man/mdX.3
index 5393969..963d221 100644
--- a/man/mdX.3
+++ b/man/mdX.3
@@ -23,6 +23,9 @@
 .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 <mdX.h>
diff --git a/man/nlist.3 b/man/nlist.3
index 6a9b367..3ee5404 100644
--- a/man/nlist.3
+++ b/man/nlist.3
@@ -35,7 +35,8 @@
 .Nm nlist
 .Nd retrieve symbol table name list from an executable file
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In nlist.h
 .Ft int
diff --git a/man/readpassphrase.3 b/man/readpassphrase.3
index bec7378..c9d55a2 100644
--- a/man/readpassphrase.3
+++ b/man/readpassphrase.3
@@ -24,6 +24,9 @@
 .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 <readpassphrase.h>
 .Ft char *
diff --git a/man/setmode.3 b/man/setmode.3
index 94fd5d1..c0a2837 100644
--- a/man/setmode.3
+++ b/man/setmode.3
@@ -36,7 +36,8 @@
 .Nm setmode
 .Nd modify mode bits
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In unistd.h
 .Ft mode_t
diff --git a/man/strlcpy.3 b/man/strlcpy.3
index 6a043e3..d32c688 100644
--- a/man/strlcpy.3
+++ b/man/strlcpy.3
@@ -35,7 +35,8 @@
 .Nm strlcat
 .Nd size-bounded string copying and concatenation
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In string.h
 .Ft size_t
diff --git a/man/strmode.3 b/man/strmode.3
index e119453..b2dfaf4 100644
--- a/man/strmode.3
+++ b/man/strmode.3
@@ -35,7 +35,8 @@
 .Nm strmode
 .Nd convert inode status information into a symbolic string
 .Sh LIBRARY
-.Lb libc
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
 .Sh SYNOPSIS
 .In string.h
 .Ft void
diff --git a/man/strtonum.3 b/man/strtonum.3
index 90f0b57..c5f3111 100644
--- a/man/strtonum.3
+++ b/man/strtonum.3
@@ -21,6 +21,9 @@
 .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 stdlib.h
 .In limits.h


More information about the libbsd mailing list