libbsd: Branch 'master' - 14 commits

Guillem Jover guillem at kemper.freedesktop.org
Mon Jun 19 02:13:53 UTC 2017


 COPYING                       |   40 +++++-
 TODO                          |    3 
 configure.ac                  |    2 
 include/Makefile.am           |    1 
 include/bsd/libutil.h         |    6 
 include/bsd/md5.h             |    6 
 include/bsd/netinet/ip_icmp.h |    4 
 include/bsd/nlist.h           |   63 ++++++++-
 include/bsd/readpassphrase.h  |    6 
 include/bsd/stringlist.h      |    6 
 include/bsd/sys/bitstring.h   |    6 
 include/bsd/sys/queue.h       |    6 
 include/bsd/sys/time.h        |  138 ++++++++++++++++++++
 include/bsd/sys/tree.h        |    6 
 include/bsd/timeconv.h        |    6 
 include/bsd/vis.h             |    6 
 man/Makefile.am               |   15 ++
 man/TIMESPEC_TO_TIMEVAL.3bsd  |    1 
 man/TIMEVAL_TO_TIMESPEC.3bsd  |    1 
 man/libbsd.7                  |    3 
 man/timeradd.3bsd             |  159 ++++++++++++++++++++++++
 man/timerclear.3bsd           |    1 
 man/timercmp.3bsd             |    1 
 man/timerisset.3bsd           |    1 
 man/timersub.3bsd             |    1 
 man/timespecadd.3bsd          |    1 
 man/timespecclear.3bsd        |    1 
 man/timespeccmp.3bsd          |    1 
 man/timespecisset.3bsd        |    1 
 man/timespecsub.3bsd          |    1 
 man/timeval.3bsd              |  133 ++++++++++++++++++++
 src/expand_number.c           |    2 
 src/flopen.c                  |    2 
 src/fmtcheck.c                |    5 
 src/fparseln.c                |    3 
 src/hash/sha512c.c            |    2 
 src/inet_net_pton.c           |    7 -
 src/merge.c                   |    4 
 src/nlist.c                   |  278 ++++++++++--------------------------------
 src/pidfile.c                 |    2 
 src/radixsort.c               |    7 -
 src/reallocf.c                |    1 
 src/setmode.c                 |    8 -
 src/stringlist.c              |    3 
 src/strlcat.c                 |   48 +++----
 src/strlcpy.c                 |   37 ++---
 src/strmode.c                 |    4 
 src/strnstr.c                 |    4 
 src/strtonum.c                |    1 
 src/timeconv.c                |    2 
 src/wcslcat.c                 |    8 -
 src/wcslcpy.c                 |    8 -
 test/.gitignore               |    7 -
 test/Makefile.am              |    4 
 test/nlist.c                  |   79 +++++++++++
 test/progname.c               |   43 ++++++
 test/setmode.c                |   45 ++++++
 test/strnstr.c                |   45 ++++++
 58 files changed, 926 insertions(+), 359 deletions(-)

New commits:
commit 8bff4b1fabde00c3ae0860b9fb83dadd7b3c6be9
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Jun 19 03:16:56 2017 +0200

    Release libbsd 0.8.4

diff --git a/configure.ac b/configure.ac
index 6b3ba2d..ae200ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,7 +13,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
 
 LIBBSD_ABI_MAJOR=0
 LIBBSD_ABI_MINOR=8
-LIBBSD_ABI_PATCH=3
+LIBBSD_ABI_PATCH=4
 
 LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
 AC_SUBST([LIBBSD_ABI])
commit 0071b97958b48fff4fa629876f92790ab3511f7e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Jun 5 05:43:26 2017 +0200

    Import <sys/time.h> for some of its macros
    
    Fixes: https://bugs.freedesktop.org/94320

diff --git a/COPYING b/COPYING
index 5b1e8c3..9ffc6b4 100644
--- a/COPYING
+++ b/COPYING
@@ -90,6 +90,7 @@ Files:
  include/bsd/netinet/ip_icmp.h
  include/bsd/sys/bitstring.h
  include/bsd/sys/queue.h
+ include/bsd/sys/time.h
  include/bsd/timeconv.h
  include/bsd/vis.h
  man/bitstring.3bsd
@@ -209,6 +210,37 @@ License: BSD-3-clause-Peter-Wemm
  SUCH DAMAGE.
 
 Files:
+ man/timeradd.3bsd
+Copyright:
+ Copyright © 2009 Jukka Ruohonen <jruohonen at iki.fi>
+ Copyright © 1999 Kelly Yancey <kbyanc at posi.net>
+ All rights reserved.
+License: BSD-3-clause-John-Birrell
+ 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 author nor the names of any co-contributors
+    may be used to endorse or promote products derived from this software
+    without specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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.
+
+Files:
  man/setproctitle.3bsd
 Copyright:
  Copyright © 1995 Peter Wemm <peter at FreeBSD.org>
@@ -235,11 +267,12 @@ Files:
  man/fmtcheck.3bsd
  man/humanize_number.3bsd
  man/stringlist.3bsd
+ man/timeval.3bsd
  src/fmtcheck.c
  src/humanize_number.c
  src/stringlist.c
 Copyright:
- Copyright © 1994, 1997-2000, 2002, 2008 The NetBSD Foundation, Inc.
+ Copyright © 1994, 1997-2000, 2002, 2008, 2010 The NetBSD Foundation, Inc.
  All rights reserved.
  .
  Some code was contributed to The NetBSD Foundation by Allen Briggs.
@@ -256,6 +289,9 @@ Copyright:
  .
  Some code is derived from software contributed to The NetBSD Foundation
  by Christos Zoulas.
+ .
+ Some code is derived from software contributed to The NetBSD Foundation
+ by Jukka Ruohonen.
 License: BSD-2-clause-NetBSD
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
diff --git a/include/Makefile.am b/include/Makefile.am
index b8140d9..6c74b44 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,6 +6,7 @@ nobase_include_HEADERS = \
 	bsd/sys/endian.h \
 	bsd/sys/poll.h \
 	bsd/sys/queue.h \
+	bsd/sys/time.h \
 	bsd/sys/tree.h \
 	bsd/netinet/ip_icmp.h \
 	bsd/bitstring.h \
diff --git a/include/bsd/sys/time.h b/include/bsd/sys/time.h
new file mode 100644
index 0000000..0aaf0e2
--- /dev/null
+++ b/include/bsd/sys/time.h
@@ -0,0 +1,138 @@
+/*	$OpenBSD: time.h,v 1.36 2016/09/12 19:41:20 guenther Exp $	*/
+/*	$NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $	*/
+
+/*
+ * Copyright (c) 1982, 1986, 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.
+ *
+ *	@(#)time.h	8.2 (Berkeley) 7/10/94
+ */
+
+#ifdef LIBBSD_OVERLAY
+#include_next <sys/time.h>
+#else
+#include <sys/time.h>
+#endif
+
+#ifndef LIBBSD_SYS_TIME_H
+#define LIBBSD_SYS_TIME_H
+
+#ifndef TIMEVAL_TO_TIMESPEC
+#define	TIMEVAL_TO_TIMESPEC(tv, ts) {					\
+	(ts)->tv_sec = (tv)->tv_sec;					\
+	(ts)->tv_nsec = (tv)->tv_usec * 1000;				\
+}
+#endif
+
+#ifndef TIMESPEC_TO_TIMEVAL
+#define	TIMESPEC_TO_TIMEVAL(tv, ts) {					\
+	(tv)->tv_sec = (ts)->tv_sec;					\
+	(tv)->tv_usec = (ts)->tv_nsec / 1000;				\
+}
+#endif
+
+/* Operations on timevals. */
+#ifndef timerclear
+#define	timerclear(tvp)		(tvp)->tv_sec = (tvp)->tv_usec = 0
+#endif
+
+#ifndef timerisset
+#define	timerisset(tvp)		((tvp)->tv_sec || (tvp)->tv_usec)
+#endif
+
+#ifndef timercmp
+#define	timercmp(tvp, uvp, cmp)						\
+	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
+	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
+	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#endif
+
+#ifndef timeradd
+#define	timeradd(tvp, uvp, vvp)						\
+	do {								\
+		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
+		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
+		if ((vvp)->tv_usec >= 1000000) {			\
+			(vvp)->tv_sec++;				\
+			(vvp)->tv_usec -= 1000000;			\
+		}							\
+	} while (0)
+#endif
+
+#ifndef timersub
+#define	timersub(tvp, uvp, vvp)						\
+	do {								\
+		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
+		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
+		if ((vvp)->tv_usec < 0) {				\
+			(vvp)->tv_sec--;				\
+			(vvp)->tv_usec += 1000000;			\
+		}							\
+	} while (0)
+#endif
+
+/* Operations on timespecs. */
+#ifndef timespecclear
+#define	timespecclear(tsp)		(tsp)->tv_sec = (tsp)->tv_nsec = 0
+#endif
+
+#ifndef timespecisset
+#define	timespecisset(tsp)		((tsp)->tv_sec || (tsp)->tv_nsec)
+#endif
+
+#ifndef timespeccmp
+#define	timespeccmp(tsp, usp, cmp)					\
+	(((tsp)->tv_sec == (usp)->tv_sec) ?				\
+	    ((tsp)->tv_nsec cmp (usp)->tv_nsec) :			\
+	    ((tsp)->tv_sec cmp (usp)->tv_sec))
+#endif
+
+#ifndef timespecadd
+#define	timespecadd(tsp, usp, vsp)					\
+	do {								\
+		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;		\
+		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;	\
+		if ((vsp)->tv_nsec >= 1000000000L) {			\
+			(vsp)->tv_sec++;				\
+			(vsp)->tv_nsec -= 1000000000L;			\
+		}							\
+	} while (0)
+#endif
+
+#ifndef timespecsub
+#define	timespecsub(tsp, usp, vsp)					\
+	do {								\
+		(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;		\
+		(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;	\
+		if ((vsp)->tv_nsec < 0) {				\
+			(vsp)->tv_sec--;				\
+			(vsp)->tv_nsec += 1000000000L;			\
+		}							\
+	} while (0)
+#endif
+
+#endif
diff --git a/man/Makefile.am b/man/Makefile.am
index 92da18d..fe0c335 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -132,6 +132,8 @@ dist_man_MANS = \
 	TAILQ_PREV.3bsd \
 	TAILQ_REMOVE.3bsd \
 	TAILQ_SWAP.3bsd \
+	TIMESPEC_TO_TIMEVAL.3bsd \
+	TIMEVAL_TO_TIMESPEC.3bsd \
 	arc4random.3bsd \
 	arc4random_addrandom.3bsd \
 	arc4random_buf.3bsd \
@@ -213,6 +215,17 @@ dist_man_MANS = \
 	strunvis.3bsd \
 	strvis.3bsd \
 	strvisx.3bsd \
+	timeradd.3bsd \
+	timerclear.3bsd \
+	timercmp.3bsd \
+	timerisset.3bsd \
+	timersub.3bsd \
+	timespecadd.3bsd \
+	timespecclear.3bsd \
+	timespeccmp.3bsd \
+	timespecisset.3bsd \
+	timespecsub.3bsd \
+	timeval.3bsd \
 	tree.3bsd \
 	unvis.3bsd \
 	vis.3bsd \
diff --git a/man/TIMESPEC_TO_TIMEVAL.3bsd b/man/TIMESPEC_TO_TIMEVAL.3bsd
new file mode 100644
index 0000000..e47176e
--- /dev/null
+++ b/man/TIMESPEC_TO_TIMEVAL.3bsd
@@ -0,0 +1 @@
+.so man3/timeval.3bsd
diff --git a/man/TIMEVAL_TO_TIMESPEC.3bsd b/man/TIMEVAL_TO_TIMESPEC.3bsd
new file mode 100644
index 0000000..e47176e
--- /dev/null
+++ b/man/TIMEVAL_TO_TIMESPEC.3bsd
@@ -0,0 +1 @@
+.so man3/timeval.3bsd
diff --git a/man/libbsd.7 b/man/libbsd.7
index 216bc01..19af0aa 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -108,6 +108,7 @@ be prefixed with
 .It In sys/endian.h
 .It In sys/poll.h
 .It In sys/queue.h
+.It In sys/time.h
 .It In sys/tree.h
 .It In timeconv.h
 .It In unistd.h
@@ -191,6 +192,8 @@ might disappear on the next SONAME bump.
 .Xr strmode 3bsd ,
 .Xr strnstr 3bsd ,
 .Xr strtonum 3bsd ,
+.Xr timeradd 3bsd ,
+.Xr timeval 3bsd ,
 .Xr tree 3bsd ,
 .Xr unvis 3bsd ,
 .Xr vis 3bsd ,
diff --git a/man/timeradd.3bsd b/man/timeradd.3bsd
new file mode 100644
index 0000000..df821de
--- /dev/null
+++ b/man/timeradd.3bsd
@@ -0,0 +1,159 @@
+.\" $NetBSD: timeradd.3,v 1.8 2010/06/07 18:40:16 jruoho Exp $
+.\"
+.\" Copyright (c) 2009 Jukka Ruohonen <jruohonen at iki.fi>
+.\" Copyright (c) 1999 Kelly Yancey <kbyanc at posi.net>
+.\" 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 author nor the names of any co-contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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.
+.\"
+.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
+.\"
+.Dd June 7, 2010
+.Dt TIMERADD 3
+.Os
+.Sh NAME
+.Nm timeradd ,
+.Nm timersub ,
+.Nm timerclear ,
+.Nm timerisset ,
+.Nm timercmp ,
+.Nm timespecadd ,
+.Nm timespecsub ,
+.Nm timespecclear ,
+.Nm timespecisset ,
+.Nm timespeccmp
+.Nd operations on time structure
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/time.h
+(See
+.Xr libbsd 7
+for include usage.)
+.Ft void
+.Fn timeradd "struct timeval *a" "struct timeval *b" "struct timeval *res"
+.Ft void
+.Fn timersub "struct timeval *a" "struct timeval *b" "struct timeval *res"
+.Ft void
+.Fn timerclear "struct timeval *tv"
+.Ft int
+.Fn timerisset "struct timeval *tv"
+.Ft int
+.Fn timercmp "struct timeval *a" "struct timeval *b" CMP
+.Ft void
+.Fn timespecadd "struct timespec *a" \
+"struct timespec *b" "struct timespec *res"
+.Ft void
+.Fn timespecsub "struct timespec *a" \
+"struct timespec *b" "struct timespec *res"
+.Ft void
+.Fn timespecclear "struct timespec *ts"
+.Ft int
+.Fn timespecisset "struct timespec *ts"
+.Ft int
+.Fn timespeccmp "struct timespec *a" "struct timespec b" CMP
+.Sh DESCRIPTION
+These macros are provided for manipulating the
+.Fa timeval
+and
+.Fa timespec
+structures described in
+.Xr timeval 3 .
+.Pp
+The
+.Fn timeradd
+and
+.Fn timespecadd
+macros add the time information stored in
+.Fa a
+to
+.Fa b ,
+storing the result in
+.Fa res .
+With
+.Fn timeradd
+the results are simplified such that the value of
+.Fa res->tv_usec
+is always less than 1,000,000 (1 second).
+With
+.Fn timespecadd
+the
+.Fa res->tv_nsec
+member of
+.Fa struct timespec
+is always less than 1,000,000,000.
+.Pp
+The
+.Fn timersub
+and
+.Fn timespecsub
+macros subtract the time information stored in
+.Fa b
+from
+.Fa a
+and store the resulting structure
+in
+.Fa res .
+.Pp
+The
+.Fn timerclear
+and
+.Fn timespecclear
+macros initialize the structures
+to midnight (0 hour) January 1st, 1970 (the Epoch).
+In other words, they set the members of the structure to zero.
+.Pp
+The
+.Fn timerisset
+and
+.Fn timespecisset
+macros return true if the input structure
+is set to any time value other than the Epoch.
+.Pp
+The
+.Fn timercmp
+and
+.Fn timespeccmp
+macros compare
+.Fa a
+to
+.Fa b
+using the comparison operator given in
+.Fa CMP .
+The result of the comparison is returned.
+.Sh SEE ALSO
+.Xr timeval 3
+.Sh HISTORY
+The
+.Fn timeradd
+family of macros first appeared in
+.Nx 1.1 .
+These were later ported to
+.Fx 2.2.6 .
+The
+.Fn timespec
+family of macros first appeared in
+.Nx 1.2 .
diff --git a/man/timerclear.3bsd b/man/timerclear.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timerclear.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timercmp.3bsd b/man/timercmp.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timercmp.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timerisset.3bsd b/man/timerisset.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timerisset.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timersub.3bsd b/man/timersub.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timersub.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecadd.3bsd b/man/timespecadd.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecadd.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecclear.3bsd b/man/timespecclear.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecclear.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespeccmp.3bsd b/man/timespeccmp.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespeccmp.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecisset.3bsd b/man/timespecisset.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecisset.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecsub.3bsd b/man/timespecsub.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecsub.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timeval.3bsd b/man/timeval.3bsd
new file mode 100644
index 0000000..8f0e3aa
--- /dev/null
+++ b/man/timeval.3bsd
@@ -0,0 +1,133 @@
+.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $
+.\"
+.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Jukka Ruohonen.
+.\"
+.\" 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 April 12, 2011
+.Dt TIMEVAL 3
+.Os
+.Sh NAME
+.Nm timeval ,
+.Nm timespec
+.Nd time structures
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/time.h
+(See
+.Xr libbsd 7
+for include usage.)
+.Ft void
+.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
+.Ft void
+.Fn TIMESPEC_TO_TIMEVAL "struct timeval *tv" "struct timespec *ts"
+.Sh DESCRIPTION
+The
+.In sys/time.h
+header, included by
+.In time.h ,
+defines various structures related to time and timers.
+.Bl -enum -offset 1n
+.It
+The following structure is used by
+.Xr gettimeofday 2 ,
+among others:
+.Bd -literal -offset indent
+struct timeval {
+	time_t		tv_sec;
+	suseconds_t	tv_usec;
+};
+.Ed
+.Pp
+The
+.Va tv_sec
+member represents the elapsed time, in whole seconds.
+The
+.Va tv_usec
+member captures rest of the elapsed time,
+represented as the number of microseconds.
+.It
+The following structure is used by
+.Xr nanosleep 2 ,
+among others:
+.Bd -literal -offset indent
+struct timespec {
+	time_t		tv_sec;
+	long		tv_nsec;
+};
+.Ed
+.Pp
+The
+.Va tv_sec
+member is again the elapsed time in whole seconds.
+The
+.Va tv_nsec
+member represents the rest of the elapsed time in nanoseconds.
+.Pp
+A microsecond is equal to one millionth of a second,
+1000 nanoseconds, or 1/1000 milliseconds.
+To ease the conversions, the macros
+.Fn TIMEVAL_TO_TIMESPEC
+and
+.Fn TIMESPEC_TO_TIMEVAL
+can be used to convert between
+.Em struct timeval
+and
+.Em struct timespec .
+.El
+.Sh EXAMPLES
+It can be stressed that the traditional
+.Tn UNIX
+.Va timeval
+and
+.Va timespec
+structures represent elapsed time, measured by the system clock.
+The following sketch implements a function suitable
+for use in a context where the
+.Va timespec
+structure is required for a conditional timeout:
+.Bd -literal -offset indent
+static void
+example(struct timespec *spec, time_t minutes)
+{
+	struct timeval elapsed;
+
+	(void)gettimeofday(&elapsed, NULL);
+
+	_DIAGASSERT(spec != NULL);
+	TIMEVAL_TO_TIMESPEC(&elapsed, spec);
+
+	/* Add the offset for timeout in minutes. */
+	spec->tv_sec = spec->tv_sec + minutes * 60;
+}
+.Ed
+.Pp
+A better alternative would use the more precise
+.Xr clock_gettime 2 .
+.Sh SEE ALSO
+.Xr timeradd 3
commit cdbb9d0555b36935aba0353caab0b97acb95614c
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jun 18 20:30:40 2017 +0200

    test: Add new strnstr() unit test

diff --git a/test/.gitignore b/test/.gitignore
index 826172d..256574c 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -18,3 +18,4 @@ progname
 setmode
 strl
 strmode
+strnstr
diff --git a/test/Makefile.am b/test/Makefile.am
index d890436..d86539a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -46,6 +46,7 @@ check_PROGRAMS = \
 	setmode \
 	strl \
 	strmode \
+	strnstr \
 	$(nil)
 
 if HAVE_LIBTESTU01
diff --git a/test/strnstr.c b/test/strnstr.c
new file mode 100644
index 0000000..6cef281
--- /dev/null
+++ b/test/strnstr.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2017 Guillem Jover <guillem at hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <string.h>
+
+int
+main(int argc, char **argv)
+{
+	const char *large = "foo bar baz";
+	const char *small = "bar";
+
+	assert(strnstr(large, "", strlen(large)) == large);
+
+	assert(strnstr(large, "quux", strlen(large)) == NULL);
+
+	assert(strnstr(large, small, 4) == NULL);
+
+	assert(strnstr(large, small, strlen(large)) == (large + 4));
+
+	return 0;
+}
commit 0365d0efdaf099dd9b1147f4e01ef1b834f48aa8
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jun 18 20:30:19 2017 +0200

    test: Add new setprogname() and getprogname() unit test

diff --git a/test/.gitignore b/test/.gitignore
index 42f6fec..826172d 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -14,6 +14,7 @@ nlist
 overlay
 proctitle-init
 proctitle
+progname
 setmode
 strl
 strmode
diff --git a/test/Makefile.am b/test/Makefile.am
index 983cefb..d890436 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -42,6 +42,7 @@ check_PROGRAMS = \
 	md5 \
 	nlist \
 	proctitle-init \
+	progname \
 	setmode \
 	strl \
 	strmode \
diff --git a/test/progname.c b/test/progname.c
new file mode 100644
index 0000000..d6d0a73
--- /dev/null
+++ b/test/progname.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2017 Guillem Jover <guillem at hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main(int argc, char **argv)
+{
+	assert(strcmp(getprogname(), "progname") == 0);
+
+	setprogname("program-name");
+	assert(strcmp(getprogname(), "program-name") == 0);
+
+	setprogname("some-dir/some-program");
+	assert(strcmp(getprogname(), "some-program") == 0);
+
+	return 0;
+}
commit 10b1328570b54159e6c06588aef0e47b2bb348c5
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jun 18 20:29:52 2017 +0200

    test: Add new setmode() and getmode() unit test

diff --git a/test/.gitignore b/test/.gitignore
index 0ba3620..42f6fec 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -14,5 +14,6 @@ nlist
 overlay
 proctitle-init
 proctitle
+setmode
 strl
 strmode
diff --git a/test/Makefile.am b/test/Makefile.am
index 4399121..983cefb 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -42,6 +42,7 @@ check_PROGRAMS = \
 	md5 \
 	nlist \
 	proctitle-init \
+	setmode \
 	strl \
 	strmode \
 	$(nil)
diff --git a/test/setmode.c b/test/setmode.c
new file mode 100644
index 0000000..c6fbcba
--- /dev/null
+++ b/test/setmode.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2017 Guillem Jover <guillem at hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <unistd.h>
+
+int
+main(int argc, char **argv)
+{
+	umask(0);
+
+	assert(getmode(setmode("0"), 0) == 0);
+
+	assert(getmode(setmode("7777"), 0) == 07777);
+	assert(getmode(setmode("1555"), 0) == 01555);
+
+	assert(getmode(setmode("ugo=rwx"), 0) == 0777);
+
+	/* FIXME: Complete unit tests. */
+
+	return 0;
+}
commit 922eff5c5ed8517b4d78553d497bb5290f0713fa
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jun 14 01:52:12 2017 +0200

    test: Add new nlist() unit test

diff --git a/test/.gitignore b/test/.gitignore
index 2872d70..0ba3620 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -10,6 +10,7 @@ headers-overlay-gen.c
 headers-system-gen.c
 humanize
 md5
+nlist
 overlay
 proctitle-init
 proctitle
diff --git a/test/Makefile.am b/test/Makefile.am
index b7387c4..4399121 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -40,6 +40,7 @@ check_PROGRAMS = \
 	fparseln \
 	fpurge \
 	md5 \
+	nlist \
 	proctitle-init \
 	strl \
 	strmode \
diff --git a/test/nlist.c b/test/nlist.c
new file mode 100644
index 0000000..a0d4046
--- /dev/null
+++ b/test/nlist.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2017 Guillem Jover <guillem at hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stddef.h>
+#include <stdio.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <nlist.h>
+
+static int data_prv_init = 50;
+extern int data_pub_init;
+extern int data_pub_uninit[2048];
+extern int *data_pub_ptr;
+
+int *data_pub_ptr = &data_prv_init;
+int data_pub_init = 10;
+int data_pub_uninit[2048];
+
+extern int
+func_pub(void);
+
+int
+func_pub(void)
+{
+	return 42;
+}
+
+int
+main(int argc, char **argv)
+{
+	struct nlist nl[] = {
+		{ .n_un.n_name = "main" },
+		{ .n_un.n_name = "func_pub" },
+		{ .n_un.n_name = "data_pub_uninit" },
+		{ .n_un.n_name = "data_pub_init" },
+		{ .n_un.n_name = "data_prv_init" },
+		{ .n_un.n_name = NULL },
+	}, *nlp;
+	int rc;
+
+	assert(*data_pub_ptr == 50);
+
+	rc = nlist(argv[0], nl);
+	assert(rc == 0);
+
+	assert(nl[0].n_type == (N_TEXT | N_EXT));
+	assert(nl[1].n_type == (N_TEXT | N_EXT));
+	assert(nl[2].n_type == (N_BSS | N_EXT));
+	assert(nl[3].n_type == (N_DATA | N_EXT));
+	assert(nl[4].n_type == (N_DATA));
+
+	return 0;
+}
commit 8e8834d8e599c0d36a5743f93984e3777eb6d35b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jun 14 02:53:35 2017 +0200

    Remove RCSID tags
    
    These are obsolete markers, and in some cases they repeat the
    information already present in the comment header.

diff --git a/src/expand_number.c b/src/expand_number.c
index 5d55884..57d875f 100644
--- a/src/expand_number.c
+++ b/src/expand_number.c
@@ -26,8 +26,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/types.h>
 #include <ctype.h>
 #include <errno.h>
diff --git a/src/flopen.c b/src/flopen.c
index b221988..aa506f5 100644
--- a/src/flopen.c
+++ b/src/flopen.c
@@ -26,8 +26,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/file.h>
 #include <sys/stat.h>
 
diff --git a/src/fmtcheck.c b/src/fmtcheck.c
index 4a18bba..7497257 100644
--- a/src/fmtcheck.c
+++ b/src/fmtcheck.c
@@ -24,11 +24,12 @@
  * 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.
+ *
+ *	from NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp
+ *	from FreeBSD: fmtcheck.c,v 1.8 2005/03/21 08:00:55 das Exp
  */
 
-/*	$NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp $	*/
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/fmtcheck.c,v 1.8 2005/03/21 08:00:55 das Exp $");
 
 #include <stdio.h>
 #include <string.h>
diff --git a/src/fparseln.c b/src/fparseln.c
index effb849..6eada04 100644
--- a/src/fparseln.c
+++ b/src/fparseln.c
@@ -25,9 +25,6 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $");
-#endif /* LIBC_SCCS and not lint */
 
 #include <assert.h>
 #include <errno.h>
diff --git a/src/hash/sha512c.c b/src/hash/sha512c.c
index c2a93be..b3c8d5e 100644
--- a/src/hash/sha512c.c
+++ b/src/hash/sha512c.c
@@ -25,8 +25,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/endian.h>
 #include <sys/types.h>
 
diff --git a/src/inet_net_pton.c b/src/inet_net_pton.c
index b0147f6..4614248 100644
--- a/src/inet_net_pton.c
+++ b/src/inet_net_pton.c
@@ -13,14 +13,11 @@
  * 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.
+ *
+ *	from FreeBSD: inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 1.8 1996/11/21 10:28:12 vixie Exp $";
-#endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $");
-
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
diff --git a/src/merge.c b/src/merge.c
index dc92b44..c43866f 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -30,11 +30,7 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)merge.c	8.2 (Berkeley) 2/14/94";
-#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 /*
  * Hybrid exponential search/linear search merge sort with hybrid
diff --git a/src/pidfile.c b/src/pidfile.c
index 4e46367..b958cc1 100644
--- a/src/pidfile.c
+++ b/src/pidfile.c
@@ -25,8 +25,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/stat.h>
diff --git a/src/radixsort.c b/src/radixsort.c
index 77ae52c..44d3a58 100644
--- a/src/radixsort.c
+++ b/src/radixsort.c
@@ -32,13 +32,6 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)radixsort.c	8.2 (Berkeley) 4/28/95";
-#else
-__RCSID("$NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
 
 /*
  * Radixsort routines.
diff --git a/src/reallocf.c b/src/reallocf.c
index a85b5a3..d81b0ab 100644
--- a/src/reallocf.c
+++ b/src/reallocf.c
@@ -25,7 +25,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 #include <stdlib.h>
 
diff --git a/src/setmode.c b/src/setmode.c
index cdc2179..f65875e 100644
--- a/src/setmode.c
+++ b/src/setmode.c
@@ -33,14 +33,6 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)setmode.c	8.2 (Berkeley) 3/25/94";
-#else
-__RCSID("$NetBSD: setmode.c,v 1.34 2012/06/25 22:32:43 abs Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 
diff --git a/src/stringlist.c b/src/stringlist.c
index 6e5e488..d025dc0 100644
--- a/src/stringlist.c
+++ b/src/stringlist.c
@@ -30,9 +30,6 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: stringlist.c,v 1.12 2007/05/09 17:10:29 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
 
 #include <assert.h>
 #include <err.h>
diff --git a/src/strmode.c b/src/strmode.c
index 8d825ae..e6afde5 100644
--- a/src/strmode.c
+++ b/src/strmode.c
@@ -27,11 +27,7 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strmode.c	8.3 (Berkeley) 8/15/94";
-#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <string.h>
diff --git a/src/strnstr.c b/src/strnstr.c
index 4de757d..9bbccdd 100644
--- a/src/strnstr.c
+++ b/src/strnstr.c
@@ -31,11 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strstr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 #include <string.h>
 
diff --git a/src/strtonum.c b/src/strtonum.c
index 6dccd97..1c722ab 100644
--- a/src/strtonum.c
+++ b/src/strtonum.c
@@ -18,7 +18,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 #include <errno.h>
 #include <limits.h>
diff --git a/src/timeconv.c b/src/timeconv.c
index 7ee5388..11f926e 100644
--- a/src/timeconv.c
+++ b/src/timeconv.c
@@ -31,8 +31,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/types.h>
 #include <timeconv.h>
 
diff --git a/src/wcslcat.c b/src/wcslcat.c
index f5f1e1e..7643fe7 100644
--- a/src/wcslcat.c
+++ b/src/wcslcat.c
@@ -25,16 +25,10 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  *	from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp
+ *	from NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp
  */
 
 #include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
 #include <sys/types.h>
 #include <wchar.h>
 
diff --git a/src/wcslcpy.c b/src/wcslcpy.c
index b104a06..73fb35d 100644
--- a/src/wcslcpy.c
+++ b/src/wcslcpy.c
@@ -25,16 +25,10 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  *	from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
+ *	from NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp
  */
 
 #include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
-__FBSDID("$FreeBSD$");
-
 #include <sys/types.h>
 #include <wchar.h>
 
commit 7938619254db81d68805b5827df36d2c5cb6ed24
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jun 14 02:45:13 2017 +0200

    Update .gitignore for headers generator

diff --git a/test/.gitignore b/test/.gitignore
index 1c60a90..2872d70 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -6,7 +6,8 @@ fgetln
 funopen
 fparseln
 fpurge
-headers-gen.c
+headers-overlay-gen.c
+headers-system-gen.c
 humanize
 md5
 overlay
commit ec5d9a685a672f77bf3f1cd40a704619aea562b6
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jun 14 02:44:37 2017 +0200

    Namespace header inclusion protection macros
    
    Use LIBBSD_, and remove trailing underscores.

diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h
index ebb6160..45b3b15 100644
--- a/include/bsd/libutil.h
+++ b/include/bsd/libutil.h
@@ -36,8 +36,8 @@
  * $FreeBSD: src/lib/libutil/libutil.h,v 1.47 2008/04/23 00:49:12 scf Exp $
  */
 
-#ifndef _LIBUTIL_H_
-#define _LIBUTIL_H_
+#ifndef LIBBSD_LIBUTIL_H
+#define LIBBSD_LIBUTIL_H
 
 #include <features.h>
 #include <sys/cdefs.h>
@@ -86,4 +86,4 @@ __END_DECLS
 #define FPARSELN_UNESCREST	0x08
 #define FPARSELN_UNESCALL	0x0f
 
-#endif /* !_LIBUTIL_H_ */
+#endif /* !LIBBSD_LIBUTIL_H */
diff --git a/include/bsd/md5.h b/include/bsd/md5.h
index 9a75fad..5f3ae46 100644
--- a/include/bsd/md5.h
+++ b/include/bsd/md5.h
@@ -12,8 +12,8 @@
  * with every copy.
  */
 
-#ifndef _MD5_H_
-#define _MD5_H_
+#ifndef LIBBSD_MD5_H
+#define LIBBSD_MD5_H
 
 #include <stdint.h>
 
@@ -51,4 +51,4 @@ char	*MD5Data(const uint8_t *, size_t, char *)
 		__attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH)));
 __END_DECLS
 
-#endif /* _MD5_H_ */
+#endif /* LIBBSD_MD5_H */
diff --git a/include/bsd/netinet/ip_icmp.h b/include/bsd/netinet/ip_icmp.h
index 45f5d72..b42699a 100644
--- a/include/bsd/netinet/ip_icmp.h
+++ b/include/bsd/netinet/ip_icmp.h
@@ -30,8 +30,8 @@
  * $FreeBSD: src/sys/netinet/ip_icmp.h,v 1.22 2004/04/07 20:46:13 imp Exp $
  */
 
-#ifndef _NETINET_IP_ICMP_H_
-#define _NETINET_IP_ICMP_H_
+#ifndef LIBBSD_NETINET_IP_ICMP_H
+#define LIBBSD_NETINET_IP_ICMP_H
 
 #include <sys/types.h>		/* uint32_t */
 #include <netinet/in.h>		/* in_addr */
diff --git a/include/bsd/readpassphrase.h b/include/bsd/readpassphrase.h
index e1dacc3..14744b8 100644
--- a/include/bsd/readpassphrase.h
+++ b/include/bsd/readpassphrase.h
@@ -20,8 +20,8 @@
  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
  */
 
-#ifndef _READPASSPHRASE_H_
-#define _READPASSPHRASE_H_
+#ifndef LIBBSD_READPASSPHRASE_H
+#define LIBBSD_READPASSPHRASE_H
 
 #define RPP_ECHO_OFF    0x00		/* Turn off echo (default). */
 #define RPP_ECHO_ON     0x01		/* Leave echo on. */
@@ -38,4 +38,4 @@ __BEGIN_DECLS
 char * readpassphrase(const char *, char *, size_t, int);
 __END_DECLS
 
-#endif /* !_READPASSPHRASE_H_ */
+#endif /* !LIBBSD_READPASSPHRASE_H */
diff --git a/include/bsd/stringlist.h b/include/bsd/stringlist.h
index e3c42e9..ff30cac 100644
--- a/include/bsd/stringlist.h
+++ b/include/bsd/stringlist.h
@@ -29,8 +29,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _STRINGLIST_H
-#define _STRINGLIST_H
+#ifndef LIBBSD_STRINGLIST_H
+#define LIBBSD_STRINGLIST_H
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
@@ -51,4 +51,4 @@ char		*sl_find(StringList *, const char *);
 int		 sl_delete(StringList *, const char *, int);
 __END_DECLS
 
-#endif /* _STRINGLIST_H */
+#endif /* LIBBSD_STRINGLIST_H */
diff --git a/include/bsd/sys/bitstring.h b/include/bsd/sys/bitstring.h
index 125ef51..f356ca7 100644
--- a/include/bsd/sys/bitstring.h
+++ b/include/bsd/sys/bitstring.h
@@ -32,8 +32,8 @@
  * $FreeBSD$
  */
 
-#ifndef _SYS_BITSTRING_H_
-#define	_SYS_BITSTRING_H_
+#ifndef LIBBSD_SYS_BITSTRING_H
+#define LIBBSD_SYS_BITSTRING_H
 
 typedef	unsigned char bitstr_t;
 
@@ -143,4 +143,4 @@ typedef	unsigned char bitstr_t;
 	*(value) = _value; \
 } while (0)
 
-#endif /* !_SYS_BITSTRING_H_ */
+#endif /* !LIBBSD_SYS_BITSTRING_H */
diff --git a/include/bsd/sys/queue.h b/include/bsd/sys/queue.h
index 55bd494..4a94ea7 100644
--- a/include/bsd/sys/queue.h
+++ b/include/bsd/sys/queue.h
@@ -30,8 +30,8 @@
  * $FreeBSD$
  */
 
-#ifndef _SYS_QUEUE_H_
-#define	_SYS_QUEUE_H_
+#ifndef LIBBSD_SYS_QUEUE_H
+#define LIBBSD_SYS_QUEUE_H
 
 #include <sys/cdefs.h>
 
@@ -691,4 +691,4 @@ struct {								\
 		(head2)->tqh_last = &(head2)->tqh_first;		\
 } while (0)
 
-#endif /* !_SYS_QUEUE_H_ */
+#endif /* !LIBBSD_SYS_QUEUE_H */
diff --git a/include/bsd/sys/tree.h b/include/bsd/sys/tree.h
index 1cce727..628bec0 100644
--- a/include/bsd/sys/tree.h
+++ b/include/bsd/sys/tree.h
@@ -27,8 +27,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef	_SYS_TREE_H_
-#define	_SYS_TREE_H_
+#ifndef LIBBSD_SYS_TREE_H
+#define LIBBSD_SYS_TREE_H
 
 #include <sys/cdefs.h>
 
@@ -762,4 +762,4 @@ name##_RB_MINMAX(struct name *head, int val)				\
 	    ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL);	\
 	     (x) = (y))
 
-#endif	/* _SYS_TREE_H_ */
+#endif /* LIBBSD_SYS_TREE_H */
diff --git a/include/bsd/timeconv.h b/include/bsd/timeconv.h
index 29e0988..e2a2c55 100644
--- a/include/bsd/timeconv.h
+++ b/include/bsd/timeconv.h
@@ -38,8 +38,8 @@
  * $FreeBSD$
  */
 
-#ifndef _TIMECONV_H_
-#define _TIMECONV_H_
+#ifndef LIBBSD_TIMECONV_H
+#define LIBBSD_TIMECONV_H
 
 #include <sys/cdefs.h>
 #include <stdint.h>
@@ -54,4 +54,4 @@ time_t _long_to_time(long tlong);
 int _time_to_int(time_t t);
 time_t _int_to_time(int tint);
 
-#endif /* _TIMECONV_H_ */
+#endif /* LIBBSD_TIMECONV_H */
diff --git a/include/bsd/vis.h b/include/bsd/vis.h
index 835d2d6..970dfdd 100644
--- a/include/bsd/vis.h
+++ b/include/bsd/vis.h
@@ -30,8 +30,8 @@
  * $FreeBSD: src/include/vis.h,v 1.11 2003/10/30 10:40:49 phk Exp $
  */
 
-#ifndef _VIS_H_
-#define	_VIS_H_
+#ifndef LIBBSD_VIS_H
+#define LIBBSD_VIS_H
 
 #include <sys/types.h>
 
@@ -85,4 +85,4 @@ ssize_t strnunvis(char *, const char *, size_t);
 int	unvis(char *, int, int *, int);
 __END_DECLS
 
-#endif /* !_VIS_H_ */
+#endif /* !LIBBSD_VIS_H */
commit 47013bc92a1d0f71477aa018068b0923fdaf6ccf
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jun 14 01:49:25 2017 +0200

    Fix broken mmap() usage in nlist() by switching to pread()
    
    The offset is not page aligned, which makes mmap() return EINVAL on
    Linux. Switch to use pread() which handles unaligned offset and non-page
    sized reads, and because we are already loading parts of the executable
    by read() calls, so there's not much point in using mmap() anyway.

diff --git a/src/nlist.c b/src/nlist.c
index e5dede0..0932f59 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -36,6 +36,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <nlist.h>
@@ -131,7 +132,6 @@ __fdnlist(int fd, struct nlist *list)
 	char *strtab = NULL;
 	Elf_Shdr *shdr = NULL;
 	Elf_Word shdr_size;
-	void *base;
 	struct stat st;
 
 	/* Make sure obj is OK */
@@ -150,12 +150,13 @@ __fdnlist(int fd, struct nlist *list)
 		return (-1);
 	}
 
-	/* mmap section header table */
-	base = mmap(NULL, (size_t)shdr_size, PROT_READ, 0, fd,
-	    (off_t)ehdr.e_shoff);
-	if (base == MAP_FAILED)
+	shdr = malloc((size_t)shdr_size);
+	if (shdr == NULL)
 		return (-1);
-	shdr = (Elf_Shdr *)base;
+
+	/* Load section header table. */
+	if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) < 0)
+		goto done;
 
 	/*
 	 * Find the symbol table entry and it's corresponding
@@ -179,16 +180,17 @@ __fdnlist(int fd, struct nlist *list)
 		goto done;
 	}
 	/*
-	 * Map string table into our address space.  This gives us
+	 * Load string table into our address space.  This gives us
 	 * an easy way to randomly access all the strings, without
 	 * making the memory allocation permanent as with malloc/free
 	 * (i.e., munmap will return it to the system).
 	 */
-	base = mmap(NULL, (size_t)symstrsize, PROT_READ, 0, fd,
-	    (off_t)symstroff);
-	if (base == MAP_FAILED)
+	strtab = malloc((size_t)symstrsize);
+	if (strtab == NULL)
+		goto done;
+
+	if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) < 0)
 		goto done;
-	strtab = (char *)base;
 
 	/*
 	 * clean out any left-over information for all valid entries.
@@ -230,6 +232,7 @@ __fdnlist(int fd, struct nlist *list)
 			name = strtab + s->st_name;
 			if (name[0] == '\0')
 				continue;
+
 			for (p = list; !ISLAST(p); p++) {
 				if ((p->n_un.n_name[0] == '_' &&
 				    strcmp(name, p->n_un.n_name+1) == 0)
@@ -244,10 +247,8 @@ __fdnlist(int fd, struct nlist *list)
 	}
   done:
 	errsave = errno;
-	if (strtab != NULL)
-		munmap(strtab, symstrsize);
-	if (shdr != NULL)
-		munmap(shdr, shdr_size);
+	free(strtab);
+	free(shdr);
 	errno = errsave;
 	return (nent);
 }
commit e8d340de9e2ce39e340dde81ee139d5631ab0049
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Jun 5 05:30:27 2017 +0200

    Remove a.out support from nlist()
    
    Some libc libraries do not have an <a.out.h> header. And a.out as an
    executable format is very much obsolete on pretty much all currently
    supported systems, even if they might still support loading such
    objects.
    
    Remove the a.out support to increase portability.

diff --git a/include/bsd/nlist.h b/include/bsd/nlist.h
index 8531f7a..cb297e8 100644
--- a/include/bsd/nlist.h
+++ b/include/bsd/nlist.h
@@ -29,11 +29,64 @@
 
 #include <sys/cdefs.h>
 
-#if __has_include(<a.out.h>)
-#include <a.out.h>
-#elif __has_include(<linux/a.out.h>)
-#include <linux/a.out.h>
-#endif
+struct nlist {
+	union {
+		char *n_name;
+		struct n_list *n_next;
+		long n_strx;
+	} n_un;
+	unsigned char n_type;
+	char n_other;
+	short n_desc;
+	unsigned long n_value;
+};
+
+#define n_hash	n_desc		/* used internally by ld(1); XXX */
+
+/*
+ * Defines for n_type.
+ */
+#define N_UNDF	0x00		/* Undefined */
+#define N_ABS	0x02		/* Absolute address */
+#define N_TEXT	0x04		/* Text segment */
+#define N_DATA	0x06		/* Data segment */
+#define N_BSS	0x08		/* Bss segment */
+#define N_INDR	0x0a		/* Alias definition */
+#define N_SIZE	0x0c		/* Pseudo type, defines a symbol's size */
+#define N_COMM	0x12		/* Common reference */
+/* GNU extensions */
+#define N_SETA	0x14		/* Absolute set element symbol */
+#define N_SETT	0x16		/* Text set element symbol */
+#define N_SETD	0x18		/* Data set element symbol */
+#define N_SETB	0x1a		/* Bss set element symbol */
+#define N_SETV	0x1c		/* Set vector symbol */
+/* end GNU extensions */
+#define N_FN	0x1e		/* File name (N_EXT on) */
+#define N_WARN	0x1e		/* Warning message (N_EXT off) */
+
+#define N_EXT	0x01		/* External (global) bit, OR'ed in */
+#define N_TYPE	0x1e		/* Mask for all the type bits */
+#define N_STAB	0xe0		/* Mask for debugger symbols -- stab(5) */
+
+#define N_NAME(p)	((p)->n_un.n_name)
+
+/*
+ * Defines for n_other.  It contains the ".type" (AUX) field in the least
+ * significant 4 bits, and the binding (for weak symbols) in the most
+ * significant 4 bits.
+ */
+#define N_AUX(p)	((p)->n_other & 0xf)
+#define N_BIND(p)	(((unsigned int)(p)->n_other >> 4) & 0xf)
+#define N_OTHER(r, v)	(((unsigned int)(r) << 4) | ((v) & 0xf))
+
+#define AUX_OBJECT	1	/* Data object */
+#define AUX_FUNC	2	/* Function */
+
+/*#define BIND_LOCAL	0	Not used */
+/*#define BIND_GLOBAL	1	Not used */
+#define BIND_WEAK	2	/* Weak binding */
+
+#define N_FORMAT	"%08x"	/* namelist value format; XXX */
 
 __BEGIN_DECLS
 extern int nlist(const char *filename, struct nlist *list);
diff --git a/src/nlist.c b/src/nlist.c
index a066935..e5dede0 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -10,7 +10,7 @@
  * 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
+ * 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.
  *
@@ -27,186 +27,29 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)nlist.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
 
 #include <sys/param.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <sys/file.h>
-#include <arpa/inet.h>
 
 #include <errno.h>
 #include <fcntl.h>
-#include <a.out.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <nlist.h>
 
-#if !defined(__NO_A_OUT_SUPPORT)
-#define _NLIST_DO_AOUT
-#endif
-#define _NLIST_DO_ELF
-
-#ifdef _NLIST_DO_ELF
 #include "local-elf.h"
-#endif
 
 #define SIZE_T_MAX 0xffffffffU
 
-#ifdef _NLIST_DO_AOUT
-static int __aout_fdnlist(int, struct nlist *);
-#ifndef N_SYMSIZE
-#define N_SYMSIZE(a)	((a).a_syms)
-#endif
-#endif
-#ifdef _NLIST_DO_ELF
-static int __elf_fdnlist(int, struct nlist *);
-#endif
-
-/* FIXME: This function is used by libkvm0, so we need to export it.
-   It is not declared in the include files though. */
+/* Note: This function is used by libkvm0, so we need to export it.
+ * It is not declared in the include files though. */
 int __fdnlist(int, struct nlist *);
 
-int
-nlist(const char *name, struct nlist *list)
-{
-	int fd, n;
-
-	fd = open(name, O_RDONLY, 0);
-	if (fd < 0)
-		return (-1);
-	n = __fdnlist(fd, list);
-	(void)close(fd);
-	return (n);
-}
-
-static struct nlist_handlers {
-	int	(*fn)(int fd, struct nlist *list);
-} nlist_fn[] = {
-#ifdef _NLIST_DO_AOUT
-	{ __aout_fdnlist },
-#endif
-#ifdef _NLIST_DO_ELF
-	{ __elf_fdnlist },
-#endif
-};
-
-int
-__fdnlist(int fd, struct nlist *list)
-{
-	size_t i;
-	int n = -1;
-
-	for (i = 0; i < sizeof(nlist_fn) / sizeof(nlist_fn[0]); i++) {
-		n = (nlist_fn[i].fn)(fd, list);
-		if (n != -1)
-			break;
-	}
-	return (n);
-}
-
 #define	ISLAST(p)	(p->n_un.n_name == 0 || p->n_un.n_name[0] == 0)
 
-#ifdef _NLIST_DO_AOUT
-static int
-__aout_fdnlist(int fd, struct nlist *list)
-{
-	struct nlist *p, *symtab;
-	caddr_t strtab, a_out_mmap;
-	off_t stroff, symoff;
-	unsigned long symsize;
-	int nent;
-	struct exec * exec;
-	struct stat st;
-
-	/* check that file is at least as large as struct exec! */
-	if ((fstat(fd, &st) < 0) || (st.st_size < sizeof(struct exec)))
-		return (-1);
-
-	/* Check for files too large to mmap. */
-	if (st.st_size > SIZE_T_MAX) {
-		errno = EFBIG;
-		return (-1);
-	}
-
-	/*
-	 * Map the whole a.out file into our address space.
-	 * We then find the string table within this area.
-	 * We do not just mmap the string table, as it probably
-	 * does not start at a page boundary - we save ourselves a
-	 * lot of nastiness by mmapping the whole file.
-	 *
-	 * This gives us an easy way to randomly access all the strings,
-	 * without making the memory allocation permanent as with
-	 * malloc/free (i.e., munmap will return it to the system).
-	 */
-	a_out_mmap = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0);
-	if (a_out_mmap == MAP_FAILED)
-		return (-1);
-
-	exec = (struct exec *)a_out_mmap;
-	if (N_BADMAG(*exec)) {
-		munmap(a_out_mmap, (size_t)st.st_size);
-		return (-1);
-	}
-
-	symoff = N_SYMOFF(*exec);
-	symsize = N_SYMSIZE(*exec);
-	stroff = symoff + symsize;
-
-	/* find the string table in our mmapped area */
-	strtab = a_out_mmap + stroff;
-	symtab = (struct nlist *)(a_out_mmap + symoff);
-
-	/*
-	 * clean out any left-over information for all valid entries.
-	 * Type and value defined to be 0 if not found; historical
-	 * versions cleared other and desc as well.  Also figure out
-	 * the largest string length so don't read any more of the
-	 * string table than we have to.
-	 *
-	 * XXX clearing anything other than n_type and n_value violates
-	 * the semantics given in the man page.
-	 */
-	nent = 0;
-	for (p = list; !ISLAST(p); ++p) {
-		p->n_type = 0;
-		p->n_other = 0;
-		p->n_desc = 0;
-		p->n_value = 0;
-		++nent;
-	}
-
-	while (symsize > 0) {
-		int soff;
-
-		symsize-= sizeof(struct nlist);
-		soff = symtab->n_un.n_strx;
-
-
-		if (soff != 0 && (symtab->n_type & N_STAB) == 0)
-			for (p = list; !ISLAST(p); p++)
-				if (!strcmp(&strtab[soff], p->n_un.n_name)) {
-					p->n_value = symtab->n_value;
-					p->n_type = symtab->n_type;
-					p->n_desc = symtab->n_desc;
-					p->n_other = symtab->n_other;
-					if (--nent <= 0)
-						break;
-				}
-		symtab++;
-	}
-	munmap(a_out_mmap, (size_t)st.st_size);
-	return (nent);
-}
-#endif
-
-#ifdef _NLIST_DO_ELF
-static void elf_sym_to_nlist(struct nlist *, Elf_Sym *, Elf_Shdr *, int);
-
 /*
  * __elf_is_okay__ - Determine if ehdr really
  * is ELF and valid for the target platform.
@@ -237,8 +80,44 @@ __elf_is_okay__(Elf_Ehdr *ehdr)
 	return retval;
 }
 
-static int
-__elf_fdnlist(int fd, struct nlist *list)
+/*
+ * Convert an Elf_Sym into an nlist structure.  This fills in only the
+ * n_value and n_type members.
+ */
+static void
+elf_sym_to_nlist(struct nlist *nl, Elf_Sym *s, Elf_Shdr *shdr, int shnum)
+{
+	nl->n_value = s->st_value;
+
+	switch (s->st_shndx) {
+	case SHN_UNDEF:
+	case SHN_COMMON:
+		nl->n_type = N_UNDF;
+		break;
+	case SHN_ABS:
+		nl->n_type = ELF_ST_TYPE(s->st_info) == STT_FILE ?
+		    N_FN : N_ABS;
+		break;
+	default:
+		if (s->st_shndx >= shnum)
+			nl->n_type = N_UNDF;
+		else {
+			Elf_Shdr *sh = shdr + s->st_shndx;
+
+			nl->n_type = sh->sh_type == SHT_PROGBITS ?
+			    (sh->sh_flags & SHF_WRITE ? N_DATA : N_TEXT) :
+			    (sh->sh_type == SHT_NOBITS ? N_BSS : N_UNDF);
+		}
+		break;
+	}
+
+	if (ELF_ST_BIND(s->st_info) == STB_GLOBAL ||
+	    ELF_ST_BIND(s->st_info) == STB_WEAK)
+		nl->n_type |= N_EXT;
+}
+
+int
+__fdnlist(int fd, struct nlist *list)
 {
 	struct nlist *p;
 	Elf_Off symoff = 0, symstroff = 0;
@@ -373,39 +252,15 @@ __elf_fdnlist(int fd, struct nlist *list)
 	return (nent);
 }
 
-/*
- * Convert an Elf_Sym into an nlist structure.  This fills in only the
- * n_value and n_type members.
- */
-static void
-elf_sym_to_nlist(struct nlist *nl, Elf_Sym *s, Elf_Shdr *shdr, int shnum)
+int
+nlist(const char *name, struct nlist *list)
 {
-	nl->n_value = s->st_value;
-
-	switch (s->st_shndx) {
-	case SHN_UNDEF:
-	case SHN_COMMON:
-		nl->n_type = N_UNDF;
-		break;
-	case SHN_ABS:
-		nl->n_type = ELF_ST_TYPE(s->st_info) == STT_FILE ?
-		    N_FN : N_ABS;
-		break;
-	default:
-		if (s->st_shndx >= shnum)
-			nl->n_type = N_UNDF;
-		else {
-			Elf_Shdr *sh = shdr + s->st_shndx;
-
-			nl->n_type = sh->sh_type == SHT_PROGBITS ?
-			    (sh->sh_flags & SHF_WRITE ? N_DATA : N_TEXT) :
-			    (sh->sh_type == SHT_NOBITS ? N_BSS : N_UNDF);
-		}
-		break;
-	}
+	int fd, n;
 
-	if (ELF_ST_BIND(s->st_info) == STB_GLOBAL ||
-	    ELF_ST_BIND(s->st_info) == STB_WEAK)
-		nl->n_type |= N_EXT;
+	fd = open(name, O_RDONLY, 0);
+	if (fd < 0)
+		return (-1);
+	n = __fdnlist(fd, list);
+	(void)close(fd);
+	return (n);
 }
-#endif /* _NLIST_DO_ELF */
commit 7aede6a999ef7b6bd2b82aed55896611331a8eea
Author: Igor Gnatenko <i.gnatenko.brain at gmail.com>
Date:   Mon Jun 27 09:21:43 2016 +0200

    Make strlcpy()/strlcat() slightly easier to read
    
    Backport new changes from OpenBSD.
    
    [guillem at hadrons.org:
     - Update copyright years in COPYING. ]
    
    References: https://svnweb.freebsd.org/base?view=revision&revision=281135
    Signed-off-by: Igor Gnatenko <i.gnatenko.brain at gmail.com>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/COPYING b/COPYING
index eedf465..5b1e8c3 100644
--- a/COPYING
+++ b/COPYING
@@ -414,7 +414,7 @@ Copyright:
  All rights reserved.
  .
  Copyright © 1996 David Mazieres <dm at uun.org>
- Copyright © 1998, 2000-2002, 2004-2005, 2007, 2010, 2012-2014
+ Copyright © 1998, 2000-2002, 2004-2005, 2007, 2010, 2012-2015
      Todd C. Miller <Todd.Miller at courtesan.com>
  Copyright © 2004 Ted Unangst
  Copyright © 2008 Damien Miller <djm at openbsd.org>
diff --git a/src/strlcat.c b/src/strlcat.c
index 21c8afb..14c53a1 100644
--- a/src/strlcat.c
+++ b/src/strlcat.c
@@ -1,7 +1,7 @@
-/*	$OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $	*/
+/*	$OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $	*/
 
 /*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
+ * Copyright (c) 1998, 2015 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
@@ -20,36 +20,36 @@
 #include <string.h>
 
 /*
- * Appends src to string dst of size siz (unlike strncat, siz is the
- * full size of dst, not space left).  At most siz-1 characters
- * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
- * Returns strlen(src) + MIN(siz, strlen(initial dst)).
- * If retval >= siz, truncation occurred.
+ * Appends src to string dst of size dsize (unlike strncat, dsize is the
+ * full size of dst, not space left).  At most dsize-1 characters
+ * will be copied.  Always NUL terminates (unless dsize <= strlen(dst)).
+ * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
+ * If retval >= dsize, truncation occurred.
  */
 size_t
-strlcat(char *dst, const char *src, size_t siz)
+strlcat(char *dst, const char *src, size_t dsize)
 {
-	char *d = dst;
-	const char *s = src;
-	size_t n = siz;
+	const char *odst = dst;
+	const char *osrc = src;
+	size_t n = dsize;
 	size_t dlen;
 
-	/* Find the end of dst and adjust bytes left but don't go past end */
-	while (n-- != 0 && *d != '\0')
-		d++;
-	dlen = d - dst;
-	n = siz - dlen;
+	/* Find the end of dst and adjust bytes left but don't go past end. */
+	while (n-- != 0 && *dst != '\0')
+		dst++;
+	dlen = dst - odst;
+	n = dsize - dlen;
 
-	if (n == 0)
-		return(dlen + strlen(s));
-	while (*s != '\0') {
-		if (n != 1) {
-			*d++ = *s;
+	if (n-- == 0)
+		return(dlen + strlen(src));
+	while (*src != '\0') {
+		if (n != 0) {
+			*dst++ = *src;
 			n--;
 		}
-		s++;
+		src++;
 	}
-	*d = '\0';
+	*dst = '\0';
 
-	return(dlen + (s - src));	/* count does not include NUL */
+	return(dlen + (src - osrc));	/* count does not include NUL */
 }
diff --git a/src/strlcpy.c b/src/strlcpy.c
index 1719d35..e9a7fe4 100644
--- a/src/strlcpy.c
+++ b/src/strlcpy.c
@@ -1,7 +1,7 @@
-/*	$OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $	*/
+/*	$OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $	*/
 
 /*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
+ * Copyright (c) 1998, 2015 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
@@ -20,32 +20,31 @@
 #include <string.h>
 
 /*
- * Copy src to string dst of size siz.  At most siz-1 characters
- * will be copied.  Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
+ * Copy string src to buffer dst of size dsize.  At most dsize-1
+ * chars will be copied.  Always NUL terminates (unless dsize == 0).
+ * Returns strlen(src); if retval >= dsize, truncation occurred.
  */
 size_t
-strlcpy(char *dst, const char *src, size_t siz)
+strlcpy(char *dst, const char *src, size_t dsize)
 {
-	char *d = dst;
-	const char *s = src;
-	size_t n = siz;
+	const char *osrc = src;
+	size_t nleft = dsize;
 
-	/* Copy as many bytes as will fit */
-	if (n != 0) {
-		while (--n != 0) {
-			if ((*d++ = *s++) == '\0')
+	/* Copy as many bytes as will fit. */
+	if (nleft != 0) {
+		while (--nleft != 0) {
+			if ((*dst++ = *src++) == '\0')
 				break;
 		}
 	}
 
-	/* Not enough room in dst, add NUL and traverse rest of src */
-	if (n == 0) {
-		if (siz != 0)
-			*d = '\0';		/* NUL-terminate dst */
-		while (*s++)
+	/* Not enough room in dst, add NUL and traverse rest of src. */
+	if (nleft == 0) {
+		if (dsize != 0)
+			*dst = '\0';		/* NUL-terminate dst */
+		while (*src++)
 			;
 	}
 
-	return(s - src - 1);	/* count does not include NUL */
+	return(src - osrc - 1);	/* count does not include NUL */
 }
commit ab5db68bae418e91ae3475721845e6282f6da860
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Jun 19 03:02:32 2017 +0200

    build: Add missing \ at end of line
    
    Fixes: commit 934b7a0ccbdc60313102f153eadc2f46853a505b

diff --git a/man/Makefile.am b/man/Makefile.am
index 19c5c78..92da18d 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -116,7 +116,7 @@ dist_man_MANS = \
 	TAILQ_FOREACH_FROM.3bsd \
 	TAILQ_FOREACH_FROM_SAFE.3bsd \
 	TAILQ_FOREACH_REVERSE.3bsd \
-	TAILQ_FOREACH_REVERSE_FROM.3bsd
+	TAILQ_FOREACH_REVERSE_FROM.3bsd \
 	TAILQ_FOREACH_REVERSE_FROM_SAFE.3bsd \
 	TAILQ_FOREACH_REVERSE_SAFE.3bsd \
 	TAILQ_FOREACH_SAFE.3bsd \
commit 5a46e4867d09b375449a145e8628edb5637b60af
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Jun 18 20:30:51 2017 +0200

    Update TODO

diff --git a/TODO b/TODO
index c2922af..7aeab0c 100644
--- a/TODO
+++ b/TODO
@@ -4,6 +4,9 @@
   - bsd_getopt.
   - timeconv?
 * Add a README.import file.
+* Update man pages:
+  - Fix references to a.out(5) and inline needed struct definitions.
+  - Document when each interface was added on every BSD, and libbsd.
 * Handle LFS properly. By default the library emits LFS objects, but might
   be used by non-LFS objects. We should either provide foo and foo64
   functions and appropriate mappings on _FILE_OFFSET_BITS=64,


More information about the libbsd mailing list