libbsd: Branch 'master' - 29 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 8 01:54:15 UTC 2019


 COPYING                  |    4 +
 TODO                     |    2 
 configure.ac             |   28 ++++++++++++
 include/Makefile.am      |    1 
 include/bsd/err.h        |   35 +++++++++++++--
 include/bsd/nlist.h      |    9 ++--
 include/bsd/sys/param.h  |   49 ++++++++++++++++++++++
 man/arc4random.3bsd      |    1 
 man/closefrom.3bsd       |    1 
 man/errc.3bsd            |    2 
 man/expand_number.3bsd   |    1 
 man/explicit_bzero.3bsd  |    1 
 man/fgetln.3bsd          |    1 
 man/fgetwln.3bsd         |    1 
 man/flopen.3bsd          |    1 
 man/fmtcheck.3bsd        |    1 
 man/fparseln.3bsd        |    1 
 man/fpurge.3bsd          |    1 
 man/funopen.3bsd         |    1 
 man/getbsize.3bsd        |    1 
 man/getpeereid.3bsd      |    1 
 man/getprogname.3bsd     |    1 
 man/heapsort.3bsd        |    1 
 man/humanize_number.3bsd |    1 
 man/libbsd.7             |   38 ++++++++---------
 man/mdX.3bsd             |    1 
 man/nlist.3bsd           |   10 +++-
 man/pidfile.3bsd         |    1 
 man/radixsort.3bsd       |    1 
 man/readpassphrase.3bsd  |    1 
 man/reallocarray.3bsd    |    1 
 man/reallocf.3bsd        |    1 
 man/setmode.3bsd         |    1 
 man/setproctitle.3bsd    |    1 
 man/stringlist.3bsd      |    1 
 man/strlcpy.3bsd         |    1 
 man/strmode.3bsd         |    1 
 man/strnstr.3bsd         |    1 
 man/strtoi.3bsd          |    4 +
 man/strtonum.3bsd        |    4 +
 man/strtou.3bsd          |    4 +
 man/timeradd.3bsd        |    1 
 man/timeval.3bsd         |    1 
 man/unvis.3bsd           |    1 
 man/vis.3bsd             |    1 
 man/wcslcpy.3bsd         |    1 
 src/Makefile.am          |   11 ++++
 src/arc4random_linux.h   |    2 
 src/arc4random_unix.h    |    2 
 src/err.c                |  104 ++++++++++++++++++++++++++++++++++++++++++-----
 src/libbsd.map           |   13 +++++
 src/local-elf.h          |   18 ++++++++
 src/local-link.h         |   14 ++++++
 src/nlist.c              |   27 +++++++++---
 src/setproctitle.c       |    5 +-
 src/unvis.c              |    6 +-
 src/vis.c                |    6 +-
 test/nlist.c             |    2 
 58 files changed, 372 insertions(+), 61 deletions(-)

New commits:
commit 5745ca03626cce0298196481dc25579063720e46
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 15:49:41 2019 +0200

    err: Add err(), warn(), errx() and warnx() familiy of functions
    
    Some systems such as Windows or musl-libc based ones do not have these
    BSD extensions. In addition libbsd itself is making use of the warnx()
    functions, so we better provide these interfaces in case they are
    missing.

diff --git a/include/bsd/err.h b/include/bsd/err.h
index 9e83260..adf08f6 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -29,11 +29,15 @@
 #include <sys/cdefs.h>
 #if __has_include_next(<err.h>)
 #include_next <err.h>
+#else
+#define LIBBSD_NEED_ERR_H_FUNCS
 #endif
 #else
 #include <bsd/sys/cdefs.h>
 #if __has_include(<err.h>)
 #include <err.h>
+#else
+#define LIBBSD_NEED_ERR_H_FUNCS
 #endif
 #endif
 
@@ -52,6 +56,26 @@ void verrc(int status, int code, const char *format, va_list ap)
 	__printflike(3, 0) __dead2;
 void errc(int status, int code, const char *format, ...)
 	__printflike(3, 4) __dead2;
+
+#ifdef LIBBSD_NEED_ERR_H_FUNCS
+void vwarn(const char *format, va_list ap)
+	__printflike(1, 0);
+void vwarnx(const char *format, va_list ap)
+	__printflike(1, 0);
+void warn(const char *format, ...)
+	__printflike(1, 2);
+void warnx(const char *format, ...)
+	__printflike(1, 2);
+
+void verr(int status, const char *format, va_list ap)
+	__printflike(2, 0) __dead2;
+void verrx(int status, const char *format, va_list ap)
+	__printflike(2, 0) __dead2;
+void err(int status, const char *format, ...)
+	__printflike(2, 3) __dead2;
+void errx(int status, const char *format, ...)
+	__printflike(2, 3) __dead2;
+#endif
 __END_DECLS
 
 #endif
diff --git a/src/err.c b/src/err.c
index 45f1b61..8f09972 100644
--- a/src/err.c
+++ b/src/err.c
@@ -26,6 +26,9 @@
  */
 
 #include <err.h>
+#ifdef LIBBSD_NEED_ERR_H_FUNCS
+#include <errno.h>
+#endif
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -73,3 +76,76 @@ errc(int status, int code, const char *format, ...)
 	verrc(status, code, format, ap);
 	va_end(ap);
 }
+
+#ifdef LIBBSD_NEED_ERR_H_FUNCS
+void
+vwarn(const char *format, va_list ap)
+{
+	vwarnc(errno, format, ap);
+}
+
+void
+warn(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	vwarnc(errno, format, ap);
+	va_end(ap);
+}
+
+void
+vwarnx(const char *format, va_list ap)
+{
+	fprintf(stderr, "%s: ", getprogname());
+	if (format)
+		vfprintf(stderr, format, ap);
+	fprintf(stderr, "\n");
+}
+
+void
+warnx(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	vwarnx(format, ap);
+	va_end(ap);
+}
+
+void
+verr(int status, const char *format, va_list ap)
+{
+	verrc(status, errno, format, ap);
+}
+
+void
+err(int status, const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	verrc(status, errno, format, ap);
+	va_end(ap);
+}
+
+void
+verrx(int eval, const char *format, va_list ap)
+{
+	fprintf(stderr, "%s: ", getprogname());
+	if (format)
+		vfprintf(stderr, format, ap);
+	fprintf(stderr, "\n");
+	exit(eval);
+}
+
+void
+errx(int eval, const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	verrx(eval, format, ap);
+	va_end(ap);
+}
+#endif
diff --git a/src/libbsd.map b/src/libbsd.map
index ce36040..caa5cd1 100644
--- a/src/libbsd.map
+++ b/src/libbsd.map
@@ -168,3 +168,16 @@ LIBBSD_0.9.1 {
     strnvis_netbsd;
     strnunvis_netbsd;
 } LIBBSD_0.9;
+
+LIBBSD_0.10.0 {
+    /* These BSD extensions are available on GNU systems, but not on other
+     * systems such as Windows or musl libc based ones. */
+    vwarn;
+    vwarnx;
+    warn;
+    warnx;
+    verr;
+    verrx;
+    err;
+    errx;
+} LIBBSD_0.9.1;
commit 9628798d7d02e5f93b8dea02677676449a1ccd6c
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 15:37:43 2019 +0200

    err: Rewrite warnc() and errc() family functions to be standalone
    
    Do not depend on the system vwarn() and verr() functions to implement
    the *c() variants, as the system might actually lack any of the <err.h>
    BSD extensions.

diff --git a/COPYING b/COPYING
index 3e7c7cc..333ed40 100644
--- a/COPYING
+++ b/COPYING
@@ -81,7 +81,7 @@ Files:
  src/fgetln.c
  src/progname.c
 Copyright:
- Copyright © 2005, 2008-2012 Guillem Jover <guillem at hadrons.org>
+ Copyright © 2005, 2008-2012, 2019 Guillem Jover <guillem at hadrons.org>
  Copyright © 2005 Hector Garcia Alvarez
  Copyright © 2005 Aurelien Jarno
  Copyright © 2006 Robert Millan
diff --git a/include/bsd/err.h b/include/bsd/err.h
index ff37e55..9e83260 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -43,15 +43,15 @@
 #include <stdarg.h>
 
 __BEGIN_DECLS
-void warnc(int code, const char *format, ...)
-	__printflike(2, 3);
 void vwarnc(int code, const char *format, va_list ap)
 	__printflike(2, 0);
+void warnc(int code, const char *format, ...)
+	__printflike(2, 3);
 
-void errc(int status, int code, const char *format, ...)
-	__printflike(3, 4) __dead2;
 void verrc(int status, int code, const char *format, va_list ap)
 	__printflike(3, 0) __dead2;
+void errc(int status, int code, const char *format, ...)
+	__printflike(3, 4) __dead2;
 __END_DECLS
 
 #endif
diff --git a/src/err.c b/src/err.c
index 4e50510..45f1b61 100644
--- a/src/err.c
+++ b/src/err.c
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2006 Robert Millan
- * Copyright © 2011 Guillem Jover <guillem at hadrons.org>
+ * Copyright © 2011, 2019 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
@@ -26,8 +26,21 @@
  */
 
 #include <err.h>
-#include <errno.h>
+#include <string.h>
 #include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void
+vwarnc(int code, const char *format, va_list ap)
+{
+	fprintf(stderr, "%s: ", getprogname());
+	if (format) {
+		vfprintf(stderr, format, ap);
+		fprintf(stderr, ": ");
+	}
+	fprintf(stderr, "%s\n", strerror(code));
+}
 
 void
 warnc(int code, const char *format, ...)
@@ -40,13 +53,15 @@ warnc(int code, const char *format, ...)
 }
 
 void
-vwarnc(int code, const char *format, va_list ap)
+verrc(int status, int code, const char *format, va_list ap)
 {
-	int tmp = errno;
-
-	errno = code;
-	vwarn(format, ap);
-	errno = tmp;
+	fprintf(stderr, "%s: ", getprogname());
+	if (format) {
+		vfprintf(stderr, format, ap);
+		fprintf(stderr, ": ");
+	}
+	fprintf(stderr, "%s\n", strerror(code));
+	exit(status);
 }
 
 void
@@ -58,10 +73,3 @@ errc(int status, int code, const char *format, ...)
 	verrc(status, code, format, ap);
 	va_end(ap);
 }
-
-void
-verrc(int status, int code, const char *format, va_list ap)
-{
-	errno = code;
-	verr(status, format, ap);
-}
commit f34a5f71d92f5625875f16a883790de75dd4477d
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 15:29:54 2019 +0200

    err: Mark error functions as non-returning with __dead2

diff --git a/include/bsd/err.h b/include/bsd/err.h
index cf043e4..ff37e55 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -47,10 +47,11 @@ void warnc(int code, const char *format, ...)
 	__printflike(2, 3);
 void vwarnc(int code, const char *format, va_list ap)
 	__printflike(2, 0);
+
 void errc(int status, int code, const char *format, ...)
-	__printflike(3, 4);
+	__printflike(3, 4) __dead2;
 void verrc(int status, int code, const char *format, va_list ap)
-	__printflike(3, 0);
+	__printflike(3, 0) __dead2;
 __END_DECLS
 
 #endif
commit 72c68868c87c1d31bc658b43c337e8c162d16997
Author: Michael Shigorin <mike at altlinux.org>
Date:   Wed Aug 7 00:02:09 2019 +0200

    Add e2k support for nlist()
    
    This is a Russian 64-bit LE VLIW architecture named Elbrus
    (formerly Elbrus 2000).
    
    [guillem at hadrons.org:
     - Place the entry in alphabetical order. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/local-elf.h b/src/local-elf.h
index 122601b..f784b12 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -100,6 +100,12 @@
 #error Unknown AVR32 endianness
 #endif
 
+#elif defined(__e2k__)
+
+#define ELF_TARG_MACH	EM_MCST_ELBRUS
+#define ELF_TARG_CLASS	ELFCLASS64
+#define ELF_TARG_DATA	ELFDATA2LSB
+
 #elif defined(__hppa__)
 
 #define ELF_TARG_MACH	EM_PARISC
commit a4323f2b1604c440e3049461ddab0bc0b3da447f
Author: Frank Schaefer <kelledin at gmail.com>
Date:   Tue May 28 16:04:54 2019 -0500

    Add AArch64 ILP32 support to nlist()
    
    Closes: !7
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/local-elf.h b/src/local-elf.h
index 9e075cf..122601b 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -74,7 +74,11 @@
 #elif defined(__aarch64__)
 
 #define ELF_TARG_MACH	EM_AARCH64
+#if defined(__ILP32__)
+#define ELF_TARG_CLASS	ELFCLASS32
+#else
 #define ELF_TARG_CLASS	ELFCLASS64
+#endif
 #if defined(__AARCH64EB__)
 #define ELF_TARG_DATA	ELFDATA2MSB
 #else
commit 4997efa59a607a2b4aa2519a50f9e51017b667d2
Author: Rosen Penev <rosenp at gmail.com>
Date:   Fri May 17 01:44:56 2019 +0000

    Add ARC support to nlist()
    
    Closes: !6
    Signed-off-by: Rosen Penev <rosenp at gmail.com>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/local-elf.h b/src/local-elf.h
index ffc53a0..9e075cf 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -55,6 +55,12 @@
 #endif
 #define ELF_TARG_DATA	ELFDATA2LSB
 
+#elif defined (__arc__)
+
+#define ELF_TARG_MACH   EM_ARC
+#define ELF_TARG_CLASS  ELFCLASS32
+#define ELF_TARG_DATA   ELFDATA2LSB
+
 #elif defined(__arm__)
 
 #define ELF_TARG_MACH	EM_ARM
commit 96202c6c14e22b2cd4c02e13d419f507858cd754
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Aug 7 00:00:15 2019 +0200

    Add a comment to note the ELF entries are sorted alphabetically
    
    This should help people wanting to add new entries.

diff --git a/src/local-elf.h b/src/local-elf.h
index 83ca253..ffc53a0 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -37,6 +37,8 @@
 
 #define ELF_TARG_VER	EV_CURRENT
 
+/* The following entries are sorted alphabetically. */
+
 #if defined(__alpha__)
 
 #define ELF_TARG_MACH	EM_ALPHA
commit 61d378f5e9c588ef4df40c48f367e5d2f39a9525
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Sun Feb 3 00:11:15 2019 +0000

    Re-allow direct use of nlist.n_name in <nlist.h>
    
    Commit e8d340de ("Remove a.out support from nlist()") introduced a copy
    of the definition of nlist from a.out.h. However, as well as having
    n_name inside n_un, on the various BSDs n_name could also be accessed
    as a direct member of nlist, and this is made use of by FreeBSD's
    usr.bin/netstat/main.c. Thus we should also add the same enclosing
    anonymous union.
    
    [guillem at hadrons.org:
     - Add a minimal unit test. ]
    
    Closes: !4
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/include/bsd/nlist.h b/include/bsd/nlist.h
index 8767117..89877ac 100644
--- a/include/bsd/nlist.h
+++ b/include/bsd/nlist.h
@@ -36,9 +36,12 @@
 struct nlist {
 	union {
 		char *n_name;
-		struct n_list *n_next;
-		long n_strx;
-	} n_un;
+		union {
+			char *n_name;
+			struct n_list *n_next;
+			long n_strx;
+		} n_un;
+	};
 	unsigned char n_type;
 	char n_other;
 	short n_desc;
diff --git a/test/nlist.c b/test/nlist.c
index c76d9e7..82e24e9 100644
--- a/test/nlist.c
+++ b/test/nlist.c
@@ -66,6 +66,8 @@ main(int argc, char **argv)
 
 	assert(*data_pub_ptr == 50);
 
+	assert(nl[0].n_name == nl[0].n_un.n_name);
+
 	rc = nlist(argv[0], nl);
 	assert(rc == 0);
 
commit 9d917aad37778a9f4a96ba358415f077f3f36f3b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Aug 7 22:58:30 2019 +0200

    nlist: Fix out-of-bounds read on strtab
    
    When doing a string comparison for a symbol name from the string table,
    we should make sure we do a bounded comparison, otherwise a non-NUL
    terminated string might make the code read out-of-bounds.
    
    Warned-by: coverity

diff --git a/src/nlist.c b/src/nlist.c
index 8aa46a2..228c220 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -236,16 +236,18 @@ __fdnlist(int fd, struct nlist *list)
 		symsize -= cc;
 		for (s = sbuf; cc > 0 && nent > 0; ++s, cc -= sizeof(*s)) {
 			char *name;
+			Elf_Word size;
 			struct nlist *p;
 
 			name = strtab + s->st_name;
 			if (name[0] == '\0')
 				continue;
+			size = symstrsize - s->st_name;
 
 			for (p = list; !ISLAST(p); p++) {
 				if ((p->n_un.n_name[0] == '_' &&
-				    strcmp(name, p->n_un.n_name+1) == 0)
-				    || strcmp(name, p->n_un.n_name) == 0) {
+				     strncmp(name, p->n_un.n_name+1, size) == 0) ||
+				    strncmp(name, p->n_un.n_name, size) == 0) {
 					elf_sym_to_nlist(p, s, shdr,
 					    ehdr.e_shnum);
 					if (--nent <= 0)
commit 18662cadfcba39607bd5f379e19cdadce5194480
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jun 15 14:33:32 2019 +0200

    nlist: Fix unbounded malloc() calls
    
    There are a couple of malloc() calls with unbounded size arguments,
    coming from the parsed file. We need to make sure the size is not
    larger than the file being parsed, otherwise we might end up with
    out of memory conditions.
    
    Reported-by: Daniel Hodson <daniel at elttam.com.au>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/nlist.c b/src/nlist.c
index d01fa55..8aa46a2 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -151,7 +151,7 @@ __fdnlist(int fd, struct nlist *list)
 	shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
 
 	/* Make sure it's not too big to mmap */
-	if (shdr_size > SIZE_T_MAX) {
+	if (shdr_size > SIZE_T_MAX || shdr_size > st.st_size) {
 		errno = EFBIG;
 		return (-1);
 	}
@@ -184,7 +184,7 @@ __fdnlist(int fd, struct nlist *list)
 	}
 
 	/* Check for files too large to mmap. */
-	if (symstrsize > SIZE_T_MAX) {
+	if (symstrsize > SIZE_T_MAX || symstrsize > st.st_size) {
 		errno = EFBIG;
 		goto done;
 	}
commit ce53f7c25f64a694550886113154ce0b201be58f
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jun 15 14:33:32 2019 +0200

    nlist: Fix pread() return value check
    
    We should check for partial reads, and not continue in those cases,
    as we are not retrying them, otherwise we might end up operating on
    uninitialized data.
    
    Reported-by: Daniel Hodson <daniel at elttam.com.au>
    Based-on-patch-by: Daniel Hodson <daniel at elttam.com.au>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/nlist.c b/src/nlist.c
index e2a7949..d01fa55 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -161,7 +161,7 @@ __fdnlist(int fd, struct nlist *list)
 		return (-1);
 
 	/* Load section header table. */
-	if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) < 0)
+	if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) != (ssize_t)shdr_size)
 		goto done;
 
 	/*
@@ -198,7 +198,7 @@ __fdnlist(int fd, struct nlist *list)
 	if (strtab == NULL)
 		goto done;
 
-	if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) < 0)
+	if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) != (ssize_t)symstrsize)
 		goto done;
 
 	/*
commit 24d1f4dd34cd86759673f736c16e671a6303f8a8
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jun 15 14:33:32 2019 +0200

    nlist: Check whether sh_link is within bounds
    
    The sh_link members should be >= e_shnum, otherwise we might do out of
    bounds read accesses on the shdr array.
    
    Reported-by: Daniel Hodson <daniel at elttam.com.au>
    Based-on-patch-by: Daniel Hodson <daniel at elttam.com.au>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/nlist.c b/src/nlist.c
index 2aa2eee..e2a7949 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -172,6 +172,9 @@ __fdnlist(int fd, struct nlist *list)
 	 */
 	for (i = 0; i < ehdr.e_shnum; i++) {
 		if (shdr[i].sh_type == SHT_SYMTAB) {
+			if (shdr[i].sh_link >= ehdr.e_shnum)
+				goto done;
+
 			symoff = shdr[i].sh_offset;
 			symsize = shdr[i].sh_size;
 			symstroff = shdr[shdr[i].sh_link].sh_offset;
commit e9529d9b4a7833049d34b4ec3bf018bdfe68c807
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jun 15 14:33:32 2019 +0200

    nlist: Check that e_shnum and e_shentsize are within bounds
    
    The e_shnum must not be 0, otherwise we will do a zero sized allocation
    and further processing of the executable will lead to out of bounds
    read/write accesses. The e_shentsize must be equal to sizeof(Elf_Shdr),
    otherwise we will perform out of bounds read accesses on the shdr array.
    
    Reported-by: Daniel Hodson <daniel at elttam.com.au>
    Based-on-patch-by: Daniel Hodson <daniel at elttam.com.au>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/nlist.c b/src/nlist.c
index 776d315..2aa2eee 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -141,6 +141,12 @@ __fdnlist(int fd, struct nlist *list)
 	    fstat(fd, &st) < 0)
 		return (-1);
 
+	if (ehdr.e_shnum == 0 ||
+	    ehdr.e_shentsize != sizeof(Elf_Shdr)) {
+		errno = ERANGE;
+		return (-1);
+	}
+
 	/* calculate section header table size */
 	shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
 
commit 3aaedb12086a77c5ea7564eb3b5b2f02f788fe61
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Jun 15 14:33:32 2019 +0200

    nlist: Check whether the nl argument is not NULL
    
    This prevents programming errors.
    
    Reported-by: Daniel Hodson <daniel at elttam.com.au>
    Based-on-patch-by: Daniel Hodson <daniel at elttam.com.au>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/nlist.3bsd b/man/nlist.3bsd
index 7dd2377..beb32a3 100644
--- a/man/nlist.3bsd
+++ b/man/nlist.3bsd
@@ -72,7 +72,10 @@ The last entry in the list is always
 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.
+does not exist or is not executable,
+or the nl pointer is
+.Dv NULL ,
+the returned value is \-1.
 .Sh SEE ALSO
 .Xr elf 5
 .Sh HISTORY
diff --git a/src/nlist.c b/src/nlist.c
index 0932f59..776d315 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -258,6 +258,10 @@ nlist(const char *name, struct nlist *list)
 {
 	int fd, n;
 
+	if (list == NULL) {
+		errno = EINVAL;
+		return (-1);
+	}
 	fd = open(name, O_RDONLY, 0);
 	if (fd < 0)
 		return (-1);
commit 2c754f435b18a642f023278fc2372f2186a4ed8b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 31 03:49:43 2019 +0200

    man: Add man page sections to function references
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/libbsd.7 b/man/libbsd.7
index 66a16cb..407b3e4 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -76,7 +76,7 @@ The package also provides a
 .Pa bsd-ctor
 static library that can be used to inject automatic constructors into a
 program so that the
-.Fn setproctitle_init
+.Fn setproctitle_init 3
 function gets invoked automatically at startup time.
 This can be done with the
 .Xr pkg-config 3
@@ -134,7 +134,7 @@ or non-buggy way; or because there are better more portable replacements now.
 .Pp
 This is the list of currently deprecated macros and functions:
 .Bl -tag -width 4m
-.It Fn fgetln
+.It Fn fgetln 3
 Unportable, requires assistance from the stdio layer.
 An implementation has to choose between leaking buffers or being reentrant
 for a limited amount of streams (this implementation chose the latter with
@@ -143,7 +143,7 @@ Use
 .Fn getline 3
 instead, which is available in many systems and required by
 .St -p1003.1-2008 .
-.It Fn fgetwln
+.It Fn fgetwln 3
 Unportable, requires assistance from the stdio layer.
 An implementation has to choose between leaking buffers or being reentrant
 for a limited amount of streams (this implementation chose the latter with
@@ -154,10 +154,10 @@ instead, which is available in many systems and required by
 .St -isoC-99
 and
 .St -p1003.1-2001 .
-.It Fn funopen
+.It Fn funopen 3
 Unportable, requires assistance from the stdio layer or some hook framework.
 On GNU systems the
-.Fn fopencookie
+.Fn fopencookie 3
 function can be used.
 Otherwise the code needs to be prepared for neither of these functions being
 available.
@@ -171,23 +171,23 @@ are present in all major
 for example.
 .Pp
 .Bl -tag -width 4m -compact
-.It Fn MD5Init
-.It Fn MD5Update
-.It Fn MD5Pad
-.It Fn MD5Final
-.It Fn MD5Transform
-.It Fn MD5End
-.It Fn MD5File
-.It Fn MD5FileChunk
-.It Fn MD5Data
+.It Fn MD5Init 3
+.It Fn MD5Update 3
+.It Fn MD5Pad 3
+.It Fn MD5Final 3
+.It Fn MD5Transform 3
+.It Fn MD5End 3
+.It Fn MD5File 3
+.It Fn MD5FileChunk 3
+.It Fn MD5Data 3
 The set of MD5 digest functions are now provided by the
 .Nm libmd
 companion library, so it is advised to use that instead.
-.It Fn explicit_bzero
+.It Fn explicit_bzero 3
 This function is provided by
 .Nm glibc
 2.25.
-.It Fn reallocarray
+.It Fn reallocarray 3
 This function is provided by
 .Nm glibc
 2.26.
commit ee4d24970a637f6002ee69ca4e6622a68265e95c
Author: Sebastian <versat82 at gmail.com>
Date:   Sun Mar 10 10:03:12 2019 +0000

    man: Fix typo
    
    Closes: !5
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/libbsd.7 b/man/libbsd.7
index 290ad19..66a16cb 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -33,7 +33,7 @@
 .Sh DESCRIPTION
 The
 .Nm libbsd
-library provides a set if compatibility macros and functions commonly found
+library provides a set of compatibility macros and functions commonly found
 on BSD-based systems.
 Its purpose is to make those available on non-BSD based systems to ease
 portability.
commit 8d2afa3a9f5cdf40d82a81dd70994d321ef62c0e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 31 03:49:24 2019 +0200

    man: Fix typos
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/libbsd.7 b/man/libbsd.7
index df9fe1a..290ad19 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -1,6 +1,6 @@
 .\" libbsd man page
 .\"
-.\" Copyright © 2017-2018 Gullem Jover <guillem at hadrons.org>
+.\" Copyright © 2017-2018 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
@@ -24,7 +24,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 21 2018
+.Dd May 21, 2018
 .Dt LIBBSD 7
 .Os
 .Sh NAME
commit e9f6faf3aabda51943e0ede5fceaaf8e7c9759bb
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 31 03:02:38 2019 +0200

    man: Replace references to a.out(5) with elf(5)
    
    The a.out(5) support in nlist(3) got removed some time ago, and
    there is now only elf(5) support.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/TODO b/TODO
index c8423f8..a4b1e45 100644
--- a/TODO
+++ b/TODO
@@ -6,7 +6,6 @@
   - 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
diff --git a/man/nlist.3bsd b/man/nlist.3bsd
index 7903ea7..7dd2377 100644
--- a/man/nlist.3bsd
+++ b/man/nlist.3bsd
@@ -51,7 +51,7 @@ The
 function
 retrieves name list entries from the symbol table of an
 executable file (see
-.Xr a.out 5 ) .
+.Xr elf 5 ) .
 The argument
 .Fa \&nl
 is set to reference the
@@ -74,7 +74,7 @@ if the file
 .Fa filename
 does not exist or is not executable, the returned value is \-1.
 .Sh SEE ALSO
-.Xr a.out 5
+.Xr elf 5
 .Sh HISTORY
 A
 .Fn nlist
commit 99320b9168ffb0112def1a712e8d59441d1b46d9
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jun 13 23:43:57 2019 +0200

    man: Define doc-operating-system-NetBSD string variables
    
    This way we do not depend on the installed groff being new enough.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/errc.3bsd b/man/errc.3bsd
index 0fa61a8..b330b6b 100644
--- a/man/errc.3bsd
+++ b/man/errc.3bsd
@@ -145,6 +145,7 @@ if ((fd = open(block_device, O_RDONLY, 0)) == -1)
 .Xr printf 3 ,
 .Xr strerror 3
 .Sh HISTORY
+.ds doc-operating-system-NetBSD-7.0 7.0
 The functions
 .Fn errc ,
 .Fn verrc ,
diff --git a/man/strtoi.3bsd b/man/strtoi.3bsd
index 00d9651..80aab7b 100644
--- a/man/strtoi.3bsd
+++ b/man/strtoi.3bsd
@@ -226,6 +226,7 @@ function is a
 .Nx
 extension.
 .Sh HISTORY
+.ds doc-operating-system-NetBSD-7.0 7.0
 The
 .Fn strtoi
 function first appeared in
diff --git a/man/strtonum.3bsd b/man/strtonum.3bsd
index 3154145..d216d00 100644
--- a/man/strtonum.3bsd
+++ b/man/strtonum.3bsd
@@ -145,6 +145,7 @@ is an
 .Ox
 extension.
 .Sh HISTORY
+.ds doc-operating-system-NetBSD-8.0 8.0
 The
 .Fn strtonum
 function first appeared in
diff --git a/man/strtou.3bsd b/man/strtou.3bsd
index e64d84e..09cc458 100644
--- a/man/strtou.3bsd
+++ b/man/strtou.3bsd
@@ -220,6 +220,7 @@ the range given was invalid, i.e.
 .Xr strtoull 3 ,
 .Xr strtoumax 3
 .Sh STANDARDS
+.ds doc-operating-system-NetBSD-7.0 7.0
 The
 .Fn strtou
 function is a
commit 71c710e9a83326023746e7e84091cd4964964ca6
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jun 13 23:42:49 2019 +0200

    man: Use major.minor version for .Nx macros
    
    The macro only recognizes this version form, and not just major alone.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/strtoi.3bsd b/man/strtoi.3bsd
index 62c441e..00d9651 100644
--- a/man/strtoi.3bsd
+++ b/man/strtoi.3bsd
@@ -229,7 +229,7 @@ extension.
 The
 .Fn strtoi
 function first appeared in
-.Nx 7 .
+.Nx 7.0 .
 .Ox
 introduced the
 .Fn strtonum 3bsd
diff --git a/man/strtonum.3bsd b/man/strtonum.3bsd
index e06347b..3154145 100644
--- a/man/strtonum.3bsd
+++ b/man/strtonum.3bsd
@@ -151,7 +151,7 @@ function first appeared in
 .Ox 3.6 .
 .Fn strtonum
 was redesigned in
-.Nx 8
+.Nx 8.0
 as
 .Fn strtoi 3bsd
 and
diff --git a/man/strtou.3bsd b/man/strtou.3bsd
index 6bdc284..e64d84e 100644
--- a/man/strtou.3bsd
+++ b/man/strtou.3bsd
@@ -229,7 +229,7 @@ extension.
 The
 .Fn strtou
 function first appeared in
-.Nx 7 .
+.Nx 7.0 .
 .Ox
 introduced the
 .Fn strtonum 3bsd
commit 21f4052c5b376800c4251462e10fa4b9630c6c69
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Jun 13 23:36:09 2019 +0200

    man: Add doc-str-Lb-libbsd aliases for str-Lb-libbsd
    
    groff(1) has changed the internal layout for the .Lb doc strings, but to
    preserve backwards compatibility we cannot simply rename them, we need
    to create new aliases so that these will work with old and new macros.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/man/arc4random.3bsd b/man/arc4random.3bsd
index 1de6508..c509a8e 100644
--- a/man/arc4random.3bsd
+++ b/man/arc4random.3bsd
@@ -42,6 +42,7 @@
 .Nd arc4 random number generator
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/closefrom.3bsd b/man/closefrom.3bsd
index d3a08c3..b2d3853 100644
--- a/man/closefrom.3bsd
+++ b/man/closefrom.3bsd
@@ -33,6 +33,7 @@
 .Nd delete open file descriptors
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In unistd.h
diff --git a/man/errc.3bsd b/man/errc.3bsd
index 954dfae..0fa61a8 100644
--- a/man/errc.3bsd
+++ b/man/errc.3bsd
@@ -38,6 +38,7 @@
 .Nd formatted error messages
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In err.h
diff --git a/man/expand_number.3bsd b/man/expand_number.3bsd
index 14327fa..e0ba501 100644
--- a/man/expand_number.3bsd
+++ b/man/expand_number.3bsd
@@ -33,6 +33,7 @@
 .Nd format a number from human readable form
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In libutil.h
diff --git a/man/explicit_bzero.3bsd b/man/explicit_bzero.3bsd
index cf67c56..ca077b3 100644
--- a/man/explicit_bzero.3bsd
+++ b/man/explicit_bzero.3bsd
@@ -37,6 +37,7 @@
 .Nd write zeroes to a byte string
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In string.h
diff --git a/man/fgetln.3bsd b/man/fgetln.3bsd
index dae47e7..c9f7059 100644
--- a/man/fgetln.3bsd
+++ b/man/fgetln.3bsd
@@ -36,6 +36,7 @@
 .Nd get a line from a stream
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
diff --git a/man/fgetwln.3bsd b/man/fgetwln.3bsd
index 71bc167..21b8695 100644
--- a/man/fgetwln.3bsd
+++ b/man/fgetwln.3bsd
@@ -36,6 +36,7 @@
 .Nd get a line of wide characters from a stream
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
diff --git a/man/flopen.3bsd b/man/flopen.3bsd
index b3cd8c9..6ee153c 100644
--- a/man/flopen.3bsd
+++ b/man/flopen.3bsd
@@ -34,6 +34,7 @@
 .Nd "Reliably open and lock a file"
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In sys/fcntl.h
diff --git a/man/fmtcheck.3bsd b/man/fmtcheck.3bsd
index 886ecb9..93e7673 100644
--- a/man/fmtcheck.3bsd
+++ b/man/fmtcheck.3bsd
@@ -34,6 +34,7 @@
 .Nd sanitizes user-supplied printf(3)-style format string
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
diff --git a/man/fparseln.3bsd b/man/fparseln.3bsd
index ab1039b..0f9ebc8 100644
--- a/man/fparseln.3bsd
+++ b/man/fparseln.3bsd
@@ -30,6 +30,7 @@
 .Nd return the next logical line from a stream
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
diff --git a/man/fpurge.3bsd b/man/fpurge.3bsd
index 435dd39..eb3fc95 100644
--- a/man/fpurge.3bsd
+++ b/man/fpurge.3bsd
@@ -39,6 +39,7 @@
 .Nd flush a stream
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
diff --git a/man/funopen.3bsd b/man/funopen.3bsd
index cc73cc1..b322525 100644
--- a/man/funopen.3bsd
+++ b/man/funopen.3bsd
@@ -40,6 +40,7 @@
 .Nd open a stream
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdio.h
diff --git a/man/getbsize.3bsd b/man/getbsize.3bsd
index d9e9e8c..d091db3 100644
--- a/man/getbsize.3bsd
+++ b/man/getbsize.3bsd
@@ -36,6 +36,7 @@
 .Nd get preferred block size
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/getpeereid.3bsd b/man/getpeereid.3bsd
index f1d2609..cce3909 100644
--- a/man/getpeereid.3bsd
+++ b/man/getpeereid.3bsd
@@ -33,6 +33,7 @@
 .Nd get the effective credentials of a UNIX-domain peer
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In sys/types.h
diff --git a/man/getprogname.3bsd b/man/getprogname.3bsd
index 013935f..d2a3e34 100644
--- a/man/getprogname.3bsd
+++ b/man/getprogname.3bsd
@@ -40,6 +40,7 @@
 .Nd get or set the program name
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/heapsort.3bsd b/man/heapsort.3bsd
index 8ec4a6d..106de56 100644
--- a/man/heapsort.3bsd
+++ b/man/heapsort.3bsd
@@ -40,6 +40,7 @@
 .Nd sort functions
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/humanize_number.3bsd b/man/humanize_number.3bsd
index d5e484c..ff1db2b 100644
--- a/man/humanize_number.3bsd
+++ b/man/humanize_number.3bsd
@@ -36,6 +36,7 @@
 .Nd format a number into a human readable form and viceversa
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/mdX.3bsd b/man/mdX.3bsd
index 248b90a..c36308a 100644
--- a/man/mdX.3bsd
+++ b/man/mdX.3bsd
@@ -25,6 +25,7 @@
 .Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In sys/types.h
diff --git a/man/nlist.3bsd b/man/nlist.3bsd
index f837000..7903ea7 100644
--- a/man/nlist.3bsd
+++ b/man/nlist.3bsd
@@ -36,6 +36,7 @@
 .Nd retrieve symbol table name list from an executable file
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In nlist.h
diff --git a/man/pidfile.3bsd b/man/pidfile.3bsd
index e8974ae..489419b 100644
--- a/man/pidfile.3bsd
+++ b/man/pidfile.3bsd
@@ -36,6 +36,7 @@
 .Nd "library for PID files handling"
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In libutil.h
diff --git a/man/radixsort.3bsd b/man/radixsort.3bsd
index 29a90c7..306a311 100644
--- a/man/radixsort.3bsd
+++ b/man/radixsort.3bsd
@@ -38,6 +38,7 @@
 .Nd radix sort
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In limits.h
diff --git a/man/readpassphrase.3bsd b/man/readpassphrase.3bsd
index 53ad52d..9887eb9 100644
--- a/man/readpassphrase.3bsd
+++ b/man/readpassphrase.3bsd
@@ -26,6 +26,7 @@
 .Nd get a passphrase from the user
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In readpassphrase.h
diff --git a/man/reallocarray.3bsd b/man/reallocarray.3bsd
index 96563ea..1a37d33 100644
--- a/man/reallocarray.3bsd
+++ b/man/reallocarray.3bsd
@@ -40,6 +40,7 @@
 .Nd memory allocation and deallocation
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/reallocf.3bsd b/man/reallocf.3bsd
index 57d6033..5d8b66d 100644
--- a/man/reallocf.3bsd
+++ b/man/reallocf.3bsd
@@ -40,6 +40,7 @@
 .Nd general purpose memory allocation functions
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stdlib.h
diff --git a/man/setmode.3bsd b/man/setmode.3bsd
index eb8f770..0710f2a 100644
--- a/man/setmode.3bsd
+++ b/man/setmode.3bsd
@@ -39,6 +39,7 @@
 .Nd modify mode bits
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In unistd.h
diff --git a/man/setproctitle.3bsd b/man/setproctitle.3bsd
index 7425b77..ad1f44f 100644
--- a/man/setproctitle.3bsd
+++ b/man/setproctitle.3bsd
@@ -28,6 +28,7 @@
 .Nd set process title
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In sys/types.h
diff --git a/man/stringlist.3bsd b/man/stringlist.3bsd
index 804aa6a..d5c0756 100644
--- a/man/stringlist.3bsd
+++ b/man/stringlist.3bsd
@@ -39,6 +39,7 @@
 .Nd stringlist manipulation functions
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In stringlist.h
diff --git a/man/strlcpy.3bsd b/man/strlcpy.3bsd
index 54a3eed..fd5d71d 100644
--- a/man/strlcpy.3bsd
+++ b/man/strlcpy.3bsd
@@ -23,6 +23,7 @@
 .Nd size-bounded string copying and concatenation
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In string.h
diff --git a/man/strmode.3bsd b/man/strmode.3bsd
index ad4a11c..224e099 100644
--- a/man/strmode.3bsd
+++ b/man/strmode.3bsd
@@ -36,6 +36,7 @@
 .Nd convert inode status information into a symbolic string
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In string.h
diff --git a/man/strnstr.3bsd b/man/strnstr.3bsd
index 0e1f5b5..e7a116d 100644
--- a/man/strnstr.3bsd
+++ b/man/strnstr.3bsd
@@ -41,6 +41,7 @@
 .Nd locate a substring in a string
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In string.h
diff --git a/man/strtoi.3bsd b/man/strtoi.3bsd
index 273d336..62c441e 100644
--- a/man/strtoi.3bsd
+++ b/man/strtoi.3bsd
@@ -44,6 +44,7 @@
 .Nd convert string value to an intmax_t integer
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In inttypes.h
diff --git a/man/strtonum.3bsd b/man/strtonum.3bsd
index 7d82fc8..e06347b 100644
--- a/man/strtonum.3bsd
+++ b/man/strtonum.3bsd
@@ -23,6 +23,7 @@
 .Nd reliably convert string value to an integer
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In limits.h
diff --git a/man/strtou.3bsd b/man/strtou.3bsd
index fc0f901..6bdc284 100644
--- a/man/strtou.3bsd
+++ b/man/strtou.3bsd
@@ -44,6 +44,7 @@
 .Nd convert a string to an uintmax_t integer
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In inttypes.h
diff --git a/man/timeradd.3bsd b/man/timeradd.3bsd
index 607383a..e9e78e9 100644
--- a/man/timeradd.3bsd
+++ b/man/timeradd.3bsd
@@ -47,6 +47,7 @@
 .Nd operations on time structure
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In sys/time.h
diff --git a/man/timeval.3bsd b/man/timeval.3bsd
index 39c4c65..31431a3 100644
--- a/man/timeval.3bsd
+++ b/man/timeval.3bsd
@@ -36,6 +36,7 @@
 .Nd time structures
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In sys/time.h
diff --git a/man/unvis.3bsd b/man/unvis.3bsd
index 693fbda..22ed7c9 100644
--- a/man/unvis.3bsd
+++ b/man/unvis.3bsd
@@ -41,6 +41,7 @@
 .Nd decode a visual representation of characters
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In vis.h
diff --git a/man/vis.3bsd b/man/vis.3bsd
index 25280a8..00d9ebe 100644
--- a/man/vis.3bsd
+++ b/man/vis.3bsd
@@ -51,6 +51,7 @@
 .Nd visually encode characters
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In vis.h
diff --git a/man/wcslcpy.3bsd b/man/wcslcpy.3bsd
index 4195581..c112ff3 100644
--- a/man/wcslcpy.3bsd
+++ b/man/wcslcpy.3bsd
@@ -44,6 +44,7 @@
 .Nd wide character string manipulation operations
 .Sh LIBRARY
 .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
 .Lb libbsd
 .Sh SYNOPSIS
 .In wchar.h
commit 1899e2c5ab19526706bbe7386171ff0f06cfaa44
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Jul 31 02:58:01 2019 +0200

    Update TODO
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/TODO b/TODO
index 7aeab0c..c8423f8 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,4 @@
+* Migrate portable functions from GNU/kFreeBSD's libfreebsd.
 * Add more functions used by ported packages (check openssh).
 * Add more unit tests.
 * Add missing man pages.
commit 480334080262a705bc029d0acb62d49900bfbe3c
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    Provide a <sys/param.h> with MIN() and MAX()
    
    Windows doesn't provide <sys/param.h>. Several libbsd sources require it
    for MIN(), and these are useful non-system-specific macros anyway.
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/COPYING b/COPYING
index 87234aa..3e7c7cc 100644
--- a/COPYING
+++ b/COPYING
@@ -74,6 +74,7 @@ License: BSD-4-clause-Christopher-G-Demetriou
 Files:
  include/bsd/err.h
  include/bsd/stdlib.h
+ include/bsd/sys/param.h
  include/bsd/unistd.h
  src/bsd_getopt.c
  src/err.c
@@ -84,6 +85,7 @@ Copyright:
  Copyright © 2005 Hector Garcia Alvarez
  Copyright © 2005 Aurelien Jarno
  Copyright © 2006 Robert Millan
+ Copyright © 2018 Facebook, Inc.
 License: BSD-3-clause
 
 Files:
diff --git a/include/Makefile.am b/include/Makefile.am
index ce3f058..949ea80 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -4,6 +4,7 @@ nobase_include_HEADERS = \
 	bsd/sys/bitstring.h \
 	bsd/sys/cdefs.h \
 	bsd/sys/endian.h \
+	bsd/sys/param.h \
 	bsd/sys/poll.h \
 	bsd/sys/queue.h \
 	bsd/sys/time.h \
diff --git a/include/bsd/sys/param.h b/include/bsd/sys/param.h
new file mode 100644
index 0000000..d971775
--- /dev/null
+++ b/include/bsd/sys/param.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2018 Facebook, Inc.
+ *
+ * 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.
+ */
+
+#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<sys/param.h>)
+#include_next <sys/param.h>
+#endif
+#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<sys/param.h>)
+#include <sys/param.h>
+#endif
+#endif
+
+#ifndef LIBBSD_SYS_PARAM_H
+#define LIBBSD_SYS_PARAM_H
+
+#ifndef MIN
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#endif
+#ifndef MAX
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#endif
+
+#endif
commit f99b8ea52737701820078e9efd59fa75f348878e
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:33 2018 -0700

    build: Disable CRT warnings on Windows
    
    These warnings are not helpful for libbsd.
    
    [guillem at hadrons.org:
     - Rename WINDOWS conditional to OS_WINDOWS.
     - Add a nil terminator to the AM_CPPFLAGS. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/Makefile.am b/src/Makefile.am
index 76222a3..8384b92 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,13 @@ AM_CPPFLAGS = \
 	-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
 	-D__REENTRANT
 
+if OS_WINDOWS
+AM_CPPFLAGS += \
+	-D_CRT_SECURE_NO_WARNINGS \
+	-D_CRT_NONSTDC_NO_WARNINGS \
+	$(nil)
+endif
+
 libbsd_la_included_sources = \
 	hash/helper.c \
 	getentropy_aix.c \
commit 4bed48398ff97b2d98cf4665b528a939c620522c
Author: Aaron Dierking <aarond at fb.com>
Date:   Thu Jun 14 11:38:32 2018 -0700

    build: Detect Windows/MinGW at configure time
    
    Extend the host OS checks to define an OS_WINDOWS automake conditional if
    the host is MinGW-like. This will be useful for future Windows-specific
    build tweaks.
    
    [guillem at hadrons.org:
     - Rename WINDOWS conditional to OS_WINDOWS. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/configure.ac b/configure.ac
index 3beb08e..aa43ce6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,7 @@ AC_SUBST([TESTU01_LIBS])
 AM_CONDITIONAL([HAVE_LIBTESTU01],
                [test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
 
+is_windows=no
 AS_CASE([$host_os],
   [*-gnu*], [
     # In old glibc versions (< 2.17) clock_gettime() is in librt.
@@ -60,7 +61,11 @@ AS_CASE([$host_os],
     # Upstream refuses to define this, we will do it ourselves then.
     AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
   ],
+  [mingw*], [
+    is_windows=yes
+  ],
 )
+AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
 
 # Checks for header files.
 AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h grp.h])
commit 2e071c3cc152ec55db7b87248fdc017a0f735302
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 19:14:29 2019 +0200

    build: Support platforms without symbol versioning
    
    The .symver directive is ELF-specific. On non-ELF platforms, work around
    this with __attribute__((__alias__)) for the default symbol, and ignore
    the variant versioned symbols.
    
    Based-on-patch-by: Aaron Dierking <aarond at fb.com>
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/local-link.h b/src/local-link.h
index 5a17bfe..0d4351a 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -31,10 +31,17 @@
 	static const char libbsd_emit_link_warning_##symbol[] \
 		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
 
+#ifdef __ELF__
 #define libbsd_symver_default(alias, symbol, version) \
 	__asm__(".symver " #symbol "," #alias "@@" #version)
 
 #define libbsd_symver_variant(alias, symbol, version) \
 	__asm__(".symver " #symbol "," #alias "@" #version)
+#else
+#define libbsd_symver_default(alias, symbol, version) \
+	extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
+
+#define libbsd_symver_variant(alias, symbol, version)
+#endif
 
 #endif
commit 890699a78b892a8591cd465f97d4967ee94d54c9
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 18:51:45 2019 +0200

    build: Abstract symbol versioning via new libbsd_symver_* macros
    
    This makes it more obvious what they are doing. It will make it easier
    to make these directives more portable, as they are really ELF specific.

diff --git a/src/local-link.h b/src/local-link.h
index 5f3c0fd..5a17bfe 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -30,4 +30,11 @@
 #define libbsd_link_warning(symbol, msg) \
 	static const char libbsd_emit_link_warning_##symbol[] \
 		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
+
+#define libbsd_symver_default(alias, symbol, version) \
+	__asm__(".symver " #symbol "," #alias "@@" #version)
+
+#define libbsd_symver_variant(alias, symbol, version) \
+	__asm__(".symver " #symbol "," #alias "@" #version)
+
 #endif
diff --git a/src/setproctitle.c b/src/setproctitle.c
index 6329bf4..ff32aa3 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <unistd.h>
 #include <string.h>
+#include "local-link.h"
 
 static struct {
 	/* Original value. */
@@ -280,7 +281,7 @@ setproctitle_impl(const char *fmt, ...)
 		*++nul = '\0';
 	}
 }
-__asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
+libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
 
 /* The original function introduced in 0.2 was a stub, it only got implemented
  * in 0.5, make the implementation available in the old version as an alias
@@ -295,4 +296,4 @@ void
 setproctitle_stub(const char *fmt, ...)
 	__attribute__((__alias__("setproctitle_impl")));
 #endif
-__asm__(".symver setproctitle_stub,setproctitle at LIBBSD_0.2");
+libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);
diff --git a/src/unvis.c b/src/unvis.c
index ae963aa..166421a 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -42,6 +42,8 @@
 #include <vis.h>
 #pragma GCC diagnostic pop
 
+#include "local-link.h"
+
 #ifdef __weak_alias
 __weak_alias(strnunvisx,_strnunvisx)
 #endif
@@ -566,11 +568,11 @@ strnunvis_openbsd(char *dst, const char *src, size_t dlen)
 {
 	return strnunvisx(dst, dlen, src, 0);
 }
-__asm__(".symver strnunvis_openbsd,strnunvis@@LIBBSD_0.2");
+libbsd_symver_default(strnunvis, strnunvis_openbsd, LIBBSD_0.2);
 
 int
 strnunvis_netbsd(char *dst, size_t dlen, const char *src)
 {
 	return strnunvisx(dst, dlen, src, 0);
 }
-__asm__(".symver strnunvis_netbsd,strnunvis at LIBBSD_0.9.1");
+libbsd_symver_variant(strnunvis, strnunvis_netbsd, LIBBSD_0.9.1);
diff --git a/src/vis.c b/src/vis.c
index 260d3c1..c8e5ae8 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -77,6 +77,8 @@ __weak_alias(strvisx,_strvisx)
 #include <stdio.h>
 #include <string.h>
 
+#include "local-link.h"
+
 #define _DIAGASSERT(x)
 
 /*
@@ -735,14 +737,14 @@ strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
 {
 	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
-__asm__(".symver strnvis_openbsd,strnvis@@LIBBSD_0.2");
+libbsd_symver_default(strnvis, strnvis_openbsd, LIBBSD_0.2);
 
 int
 strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
 {
 	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
-__asm__(".symver strnvis_netbsd,strnvis at LIBBSD_0.9.1");
+libbsd_symver_variant(strnvis, strnvis_netbsd, LIBBSD_0.9.1);
 
 int
 stravis(char **mbdstp, const char *mbsrc, int flags)
commit b0ebb0d4c26b281facbab7a774510b541637b13b
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 23:16:42 2019 +0200

    build: Use __register_atfork() only if really available
    
    This is a glibc-specific symbol that has no public declaration. But is
    being used by the OpenBSD and this implementation as a hack to avoid
    having to link against the pthread library. This interface is at least
    included in LSB 5.0 [L], and using pthread_atfork() is otherwise
    problematic anyway [P].
    
     [L] <https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib---register-atfork.html>
     [P] <http://austingroupbugs.net/view.php?id=851>
    
    One problem is that we were using it whenever __GLIBC__ is defined,
    which is supposed to be defined only on an actual glibc, but uClibc
    defines that macro, but it does not provide the symbol on its noMMU
    variant.
    
    We add a new configure check that will try to link a program that uses
    that symbol to make sure it is present.
    
    Closes: !2
    Reported-by: Fabrice Fontaine <fontaine.fabrice at gmail.com>

diff --git a/configure.ac b/configure.ac
index 1654072..3beb08e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,6 +145,23 @@ AC_LINK_IFELSE(
 	 AC_MSG_RESULT([yes])],
 	[AC_MSG_RESULT([no])])
 
+AC_MSG_CHECKING([for __register_atfork])
+AC_LINK_IFELSE(
+	[AC_LANG_PROGRAM([[
+		#include <stddef.h>
+		extern void *__dso_handle;
+		extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
+	]], [[
+		__register_atfork(NULL, NULL, NULL, __dso_handle);
+	]])],
+	[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
+	           [Define to 1 if you have __register_atfork])
+	 AC_MSG_RESULT([yes])],
+	[ARC4RANDOM_ATFORK_LIBS="-pthread"
+	 AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
+	 AC_MSG_RESULT([no])
+	])
+
 AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
                 getauxval getentropy getexecname getline \
                 pstat_getproc sysconf])
diff --git a/src/Makefile.am b/src/Makefile.am
index f3cc0fa..76222a3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,7 +54,9 @@ libbsd_la_DEPENDENCIES = \
 	$(libbsd_la_included_sources) \
 	libbsd.map
 libbsd_la_LIBADD = \
-	$(CLOCK_GETTIME_LIBS)
+	$(CLOCK_GETTIME_LIBS) \
+	$(ARC4RANDOM_ATFORK_LIBS) \
+	$(nil)
 libbsd_la_LDFLAGS = \
 	-Wl,--version-script=$(srcdir)/libbsd.map \
 	-version-number $(LIBBSD_ABI)
diff --git a/src/arc4random_linux.h b/src/arc4random_linux.h
index 7a2ca1e..bc57cd1 100644
--- a/src/arc4random_linux.h
+++ b/src/arc4random_linux.h
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
 #define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
 #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
 
-#ifdef __GLIBC__
+#ifdef HAVE___REGISTER_ATFORK
 extern void *__dso_handle;
 extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
 #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
diff --git a/src/arc4random_unix.h b/src/arc4random_unix.h
index 0e37683..2e6c6ea 100644
--- a/src/arc4random_unix.h
+++ b/src/arc4random_unix.h
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
 #define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
 #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
 
-#ifdef __GLIBC__
+#ifdef HAVE___REGISTER_ATFORK
 extern void *__dso_handle;
 extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
 #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
commit 73aea4f8083e8c35ce1123e36a9967ecd6a26c97
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 6 23:11:50 2019 +0200

    build: Fix check for clock_gettime() within librt
    
    The check was always setting the libraries to link to include -lrt,
    as the success case includes the builtin one. Handle the various
    values.

diff --git a/configure.ac b/configure.ac
index 6b2bb6c..1654072 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,7 +48,11 @@ AS_CASE([$host_os],
   [*-gnu*], [
     # In old glibc versions (< 2.17) clock_gettime() is in librt.
     saved_LIBS="$LIBS"
-    AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"])
+    AC_SEARCH_LIBS([clock_gettime], [rt], [
+      AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
+        CLOCK_GETTIME_LIBS="$ac_cv_search_clock_gettime"
+      ])
+    ])
     AC_SUBST([CLOCK_GETTIME_LIBS])
     LIBS="$saved_LIBS"
   ],


More information about the libbsd mailing list