libbsd: Branch 'main' - 5 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 1 03:32:26 UTC 2021


 .gitignore               |    1 
 COPYING                  |    2 
 configure.ac             |   14 -
 man/tree.3bsd            |  391 ++++++++++++++++++++++++++++-------------------
 src/Makefile.am          |   33 +++
 src/fgetln.c             |    2 
 src/fgetwln.c            |    2 
 src/libbsd-overlay.pc.in |    2 
 src/libbsd.pc.in         |    2 
 src/local-link.h         |   11 +
 src/md5.c                |  112 +++++--------
 test/Makefile.am         |    5 
 12 files changed, 340 insertions(+), 237 deletions(-)

New commits:
commit fafcc397accedf1b8c3ef451cafa5f008bdb071d
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Nov 30 04:00:54 2021 +0100

    man: Update tree(3) man page from OpenBSD
    
    This man page has a BSD-3-clause-author license instead of the old
    BSD-4-clause license.

diff --git a/COPYING b/COPYING
index 8a99303..32a1130 100644
--- a/COPYING
+++ b/COPYING
@@ -8,7 +8,6 @@ License: BSD-3-clause
 
 Files:
  man/arc4random.3bsd
- man/tree.3bsd
 Copyright:
  Copyright 1997 Niels Provos <provos at physnet.uni-hamburg.de>
  All rights reserved.
@@ -348,6 +347,7 @@ License: BSD-2-clause-verbatim
 Files:
  include/bsd/sys/tree.h
  man/fparseln.3bsd
+ man/tree.3bsd
  src/fparseln.c
 Copyright:
  Copyright © 1997 Christos Zoulas.
diff --git a/man/tree.3bsd b/man/tree.3bsd
index 6800c74..9433394 100644
--- a/man/tree.3bsd
+++ b/man/tree.3bsd
@@ -1,36 +1,29 @@
-.\"	$OpenBSD: tree.3,v 1.7 2002/06/12 01:09:20 provos Exp $
-.\"
-.\" Copyright 2002 Niels Provos <provos at citi.umich.edu>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"      This product includes software developed by Niels Provos.
-.\" 4. The name of the author may not be used to endorse or promote products
-.\"    derived from this software without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd December 27, 2007
+.\"	$OpenBSD: tree.3,v 1.30 2019/05/10 13:13:14 florian Exp $
+.\"/*
+.\" * Copyright 2002 Niels Provos <provos at citi.umich.edu>
+.\" * All rights reserved.
+.\" *
+.\" * Redistribution and use in source and binary forms, with or without
+.\" * modification, are permitted provided that the following conditions
+.\" * are met:
+.\" * 1. Redistributions of source code must retain the above copyright
+.\" *    notice, this list of conditions and the following disclaimer.
+.\" * 2. Redistributions in binary form must reproduce the above copyright
+.\" *    notice, this list of conditions and the following disclaimer in the
+.\" *    documentation and/or other materials provided with the distribution.
+.\" *
+.\" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\" */
+.Dd May 10 2019
 .Dt TREE 3bsd
 .Os
 .Sh NAME
@@ -70,7 +63,9 @@
 .Nm RB_RIGHT ,
 .Nm RB_PARENT ,
 .Nm RB_FOREACH ,
+.Nm RB_FOREACH_SAFE ,
 .Nm RB_FOREACH_REVERSE ,
+.Nm RB_FOREACH_REVERSE_SAFE ,
 .Nm RB_INIT ,
 .Nm RB_INSERT ,
 .Nm RB_REMOVE
@@ -84,88 +79,92 @@
 (See
 .Xr libbsd 7
 for include usage.)
-.Fn SPLAY_PROTOTYPE NAME TYPE FIELD CMP
-.Fn SPLAY_GENERATE NAME TYPE FIELD CMP
-.Fn SPLAY_ENTRY TYPE
-.Fn SPLAY_HEAD HEADNAME TYPE
+.Pp
+.Fn SPLAY_PROTOTYPE "NAME" "TYPE" "FIELD" "CMP"
+.Fn SPLAY_GENERATE "NAME" "TYPE" "FIELD" "CMP"
+.Fn SPLAY_ENTRY "TYPE"
+.Fn SPLAY_HEAD "HEADNAME" "TYPE"
 .Ft "struct TYPE *"
 .Fn SPLAY_INITIALIZER "SPLAY_HEAD *head"
 .Fn SPLAY_ROOT "SPLAY_HEAD *head"
-.Ft bool
+.Ft "int"
 .Fn SPLAY_EMPTY "SPLAY_HEAD *head"
 .Ft "struct TYPE *"
-.Fn SPLAY_NEXT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Fn SPLAY_NEXT "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
-.Fn SPLAY_MIN NAME "SPLAY_HEAD *head"
+.Fn SPLAY_MIN "NAME" "SPLAY_HEAD *head"
 .Ft "struct TYPE *"
-.Fn SPLAY_MAX NAME "SPLAY_HEAD *head"
+.Fn SPLAY_MAX "NAME" "SPLAY_HEAD *head"
 .Ft "struct TYPE *"
-.Fn SPLAY_FIND NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Fn SPLAY_FIND "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
 .Fn SPLAY_LEFT "struct TYPE *elm" "SPLAY_ENTRY NAME"
 .Ft "struct TYPE *"
 .Fn SPLAY_RIGHT "struct TYPE *elm" "SPLAY_ENTRY NAME"
-.Fn SPLAY_FOREACH VARNAME NAME "SPLAY_HEAD *head"
+.Fn SPLAY_FOREACH "VARNAME" "NAME" "SPLAY_HEAD *head"
 .Ft void
 .Fn SPLAY_INIT "SPLAY_HEAD *head"
 .Ft "struct TYPE *"
-.Fn SPLAY_INSERT NAME "SPLAY_HEAD *head" "struct TYPE *elm"
+.Fn SPLAY_INSERT "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
-.Fn SPLAY_REMOVE NAME "SPLAY_HEAD *head" "struct TYPE *elm"
-.Fn RB_PROTOTYPE NAME TYPE FIELD CMP
-.Fn RB_PROTOTYPE_STATIC NAME TYPE FIELD CMP
-.Fn RB_GENERATE NAME TYPE FIELD CMP
-.Fn RB_GENERATE_STATIC NAME TYPE FIELD CMP
-.Fn RB_ENTRY TYPE
-.Fn RB_HEAD HEADNAME TYPE
+.Fn SPLAY_REMOVE "NAME" "SPLAY_HEAD *head" "struct TYPE *elm"
+.Pp
+.Fn RB_PROTOTYPE "NAME" "TYPE" "FIELD" "CMP"
+.Fn RB_PROTOTYPE_STATIC "NAME" "TYPE" "FIELD" "CMP"
+.Fn RB_GENERATE "NAME" "TYPE" "FIELD" "CMP"
+.Fn RB_GENERATE_STATIC "NAME" "TYPE" "FIELD" "CMP"
+.Fn RB_ENTRY "TYPE"
+.Fn RB_HEAD "HEADNAME" "TYPE"
 .Fn RB_INITIALIZER "RB_HEAD *head"
 .Ft "struct TYPE *"
 .Fn RB_ROOT "RB_HEAD *head"
-.Ft "bool"
+.Ft "int"
 .Fn RB_EMPTY "RB_HEAD *head"
 .Ft "struct TYPE *"
-.Fn RB_NEXT NAME "RB_HEAD *head" "struct TYPE *elm"
+.Fn RB_NEXT "NAME" "RB_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
-.Fn RB_PREV NAME "RB_HEAD *head" "struct TYPE *elm"
+.Fn RB_PREV "NAME" "RB_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
-.Fn RB_MIN NAME "RB_HEAD *head"
+.Fn RB_MIN "NAME" "RB_HEAD *head"
 .Ft "struct TYPE *"
-.Fn RB_MAX NAME "RB_HEAD *head"
+.Fn RB_MAX "NAME" "RB_HEAD *head"
 .Ft "struct TYPE *"
-.Fn RB_FIND NAME "RB_HEAD *head" "struct TYPE *elm"
+.Fn RB_FIND "NAME" "RB_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
-.Fn RB_NFIND NAME "RB_HEAD *head" "struct TYPE *elm"
+.Fn RB_NFIND "NAME" "RB_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
 .Fn RB_LEFT "struct TYPE *elm" "RB_ENTRY NAME"
 .Ft "struct TYPE *"
 .Fn RB_RIGHT "struct TYPE *elm" "RB_ENTRY NAME"
 .Ft "struct TYPE *"
 .Fn RB_PARENT "struct TYPE *elm" "RB_ENTRY NAME"
-.Fn RB_FOREACH VARNAME NAME "RB_HEAD *head"
-.Fn RB_FOREACH_REVERSE VARNAME NAME "RB_HEAD *head"
+.Fn RB_FOREACH "VARNAME" "NAME" "RB_HEAD *head"
+.Fn RB_FOREACH_SAFE "VARNAME" "NAME" "RB_HEAD *head" "TEMP_VARNAME"
+.Fn RB_FOREACH_REVERSE "VARNAME" "NAME" "RB_HEAD *head"
+.Fn RB_FOREACH_REVERSE_SAFE "VARNAME" "NAME" "RB_HEAD *head" "TEMP_VARNAME"
 .Ft void
 .Fn RB_INIT "RB_HEAD *head"
 .Ft "struct TYPE *"
-.Fn RB_INSERT NAME "RB_HEAD *head" "struct TYPE *elm"
+.Fn RB_INSERT "NAME" "RB_HEAD *head" "struct TYPE *elm"
 .Ft "struct TYPE *"
-.Fn RB_REMOVE NAME "RB_HEAD *head" "struct TYPE *elm"
+.Fn RB_REMOVE "NAME" "RB_HEAD *head" "struct TYPE *elm"
 .Sh DESCRIPTION
 These macros define data structures for different types of trees:
 splay trees and red-black trees.
 .Pp
 In the macro definitions,
 .Fa TYPE
-is the name tag of a user defined structure that must contain a field of type
-.Vt SPLAY_ENTRY ,
+is the name tag of a user defined structure that must contain a field named
+.Fa FIELD ,
+of type
+.Li SPLAY_ENTRY
 or
-.Vt RB_ENTRY ,
-named
-.Fa ENTRYNAME .
+.Li RB_ENTRY .
 The argument
 .Fa HEADNAME
 is the name tag of a user defined structure that must be declared
 using the macros
-.Fn SPLAY_HEAD ,
+.Fn SPLAY_HEAD
 or
 .Fn RB_HEAD .
 The argument
@@ -173,46 +172,38 @@ The argument
 has to be a unique name prefix for every tree that is defined.
 .Pp
 The function prototypes are declared with
-.Fn SPLAY_PROTOTYPE ,
-.Fn RB_PROTOTYPE ,
+.Li SPLAY_PROTOTYPE ,
+.Li RB_PROTOTYPE ,
 or
-.Fn RB_PROTOTYPE_STATIC .
+.Li RB_PROTOTYPE_STATIC .
 The function bodies are generated with
-.Fn SPLAY_GENERATE ,
-.Fn RB_GENERATE ,
+.Li SPLAY_GENERATE ,
+.Li RB_GENERATE ,
 or
-.Fn RB_GENERATE_STATIC .
+.Li RB_GENERATE_STATIC .
 See the examples below for further explanation of how these macros are used.
 .Sh SPLAY TREES
 A splay tree is a self-organizing data structure.
 Every operation on the tree causes a splay to happen.
-The splay moves the requested
-node to the root of the tree and partly rebalances it.
+The splay moves the requested node to the root of the tree and partly
+rebalances it.
 .Pp
 This has the benefit that request locality causes faster lookups as
 the requested nodes move to the top of the tree.
 On the other hand, every lookup causes memory writes.
 .Pp
-The Balance Theorem bounds the total access time for
-.Ar m
-operations and
-.Ar n
-inserts on an initially empty tree as
-.Fn O "\*[lp]m + n\*[rp]lg n" .
-The
-amortized cost for a sequence of
-.Ar m
-accesses to a splay tree is
-.Fn O "lg n" .
+The Balance Theorem bounds the total access time for m operations
+and n inserts on an initially empty tree as O((m + n)lg n).
+The amortized cost for a sequence of m accesses to a splay tree is O(lg n).
 .Pp
 A splay tree is headed by a structure defined by the
 .Fn SPLAY_HEAD
 macro.
 A
+.Fa SPLAY_HEAD
 structure is declared as follows:
-.Bd -ragged -offset indent
-.Fn SPLAY_HEAD HEADNAME TYPE
-.Va head ;
+.Bd -literal -offset indent
+SPLAY_HEAD(HEADNAME, TYPE) head;
 .Ed
 .Pp
 where
@@ -251,16 +242,15 @@ macro, but should be used only once.
 Finally,
 the
 .Fa CMP
-argument is the name of a function used to compare tree nodes
+argument is the name of a function used to compare trees' nodes
 with each other.
 The function takes two arguments of type
-.Vt "struct TYPE *" .
+.Fa "struct TYPE *" .
 If the first argument is smaller than the second, the function returns a
 value smaller than zero.
 If they are equal, the function returns zero.
 Otherwise, it should return a value greater than zero.
-The compare
-function defines the order of the tree elements.
+The compare function defines the order of the tree elements.
 .Pp
 The
 .Fn SPLAY_INIT
@@ -270,11 +260,8 @@ macro initializes the tree referenced by
 The splay tree can also be initialized statically by using the
 .Fn SPLAY_INITIALIZER
 macro like this:
-.Bd -ragged -offset indent
-.Fn SPLAY_HEAD HEADNAME TYPE
-.Va head
-=
-.Fn SPLAY_INITIALIZER &head ;
+.Bd -literal -offset indent
+SPLAY_HEAD(HEADNAME, TYPE) head = SPLAY_INITIALIZER(&head);
 .Ed
 .Pp
 The
@@ -282,6 +269,11 @@ The
 macro inserts the new element
 .Fa elm
 into the tree.
+Upon success,
+.Va NULL
+is returned.
+If a matching element already exists in the tree, the insertion is
+aborted, and a pointer to the existing element is returned.
 .Pp
 The
 .Fn SPLAY_REMOVE
@@ -289,6 +281,11 @@ macro removes the element
 .Fa elm
 from the tree pointed by
 .Fa head .
+Upon success, a pointer to the removed element is returned.
+.Va NULL
+is returned if
+.Fa elm
+is not present in the tree.
 .Pp
 The
 .Fn SPLAY_FIND
@@ -296,7 +293,7 @@ macro can be used to find a particular element in the tree.
 .Bd -literal -offset indent
 struct TYPE find, *res;
 find.key = 30;
-res = SPLAY_FIND(NAME, head, &find);
+res = SPLAY_FIND(NAME, &head, &find);
 .Ed
 .Pp
 The
@@ -313,8 +310,8 @@ for (np = SPLAY_MIN(NAME, &head); np != NULL; np = SPLAY_NEXT(NAME, &head, np))
 Or, for simplicity, one can use the
 .Fn SPLAY_FOREACH
 macro:
-.Bd -ragged -offset indent
-.Fn SPLAY_FOREACH np NAME head
+.Bd -literal -offset indent
+SPLAY_FOREACH(np, NAME, &head)
 .Ed
 .Pp
 The
@@ -324,29 +321,28 @@ macro should be used to check whether a splay tree is empty.
 A red-black tree is a binary search tree with the node color as an
 extra attribute.
 It fulfills a set of conditions:
-.Bl -enum -offset indent
+.Pp
+.Bl -enum -compact -offset indent
 .It
-Every search path from the root to a leaf consists of the same number of
-black nodes.
+every search path from the root to a leaf consists of the same number of
+black nodes,
 .It
-Each red node (except for the root) has a black parent.
+each red node (except for the root) has a black parent,
 .It
-Each leaf node is black.
+each leaf node is black.
 .El
 .Pp
-Every operation on a red-black tree is bounded as
-.Fn O "lg n" .
-The maximum height of a red-black tree is
-.Fn 2lg "n + 1" .
+Every operation on a red-black tree is bounded as O(lg n).
+The maximum height of a red-black tree is 2lg (n+1).
 .Pp
 A red-black tree is headed by a structure defined by the
 .Fn RB_HEAD
 macro.
 A
+.Fa RB_HEAD
 structure is declared as follows:
-.Bd -ragged -offset indent
-.Fn RB_HEAD HEADNAME TYPE
-.Va head ;
+.Bd -literal -offset indent
+RB_HEAD(HEADNAME, TYPE) head;
 .Ed
 .Pp
 where
@@ -364,7 +360,7 @@ their prototypes need to be declared with the
 .Fn RB_PROTOTYPE
 or
 .Fn RB_PROTOTYPE_STATIC
-macro,
+macros,
 where
 .Fa NAME
 is a unique identifier for this particular tree.
@@ -381,7 +377,7 @@ The function bodies are generated with the
 .Fn RB_GENERATE
 or
 .Fn RB_GENERATE_STATIC
-macro.
+macros.
 These macros take the same arguments as the
 .Fn RB_PROTOTYPE
 and
@@ -391,16 +387,15 @@ macros, but should be used only once.
 Finally,
 the
 .Fa CMP
-argument is the name of a function used to compare tree nodes
+argument is the name of a function used to compare trees' nodes
 with each other.
 The function takes two arguments of type
-.Vt "struct TYPE *" .
+.Fa "struct TYPE *" .
 If the first argument is smaller than the second, the function returns a
 value smaller than zero.
 If they are equal, the function returns zero.
 Otherwise, it should return a value greater than zero.
-The compare
-function defines the order of the tree elements.
+The compare function defines the order of the tree elements.
 .Pp
 The
 .Fn RB_INIT
@@ -410,11 +405,8 @@ macro initializes the tree referenced by
 The red-black tree can also be initialized statically by using the
 .Fn RB_INITIALIZER
 macro like this:
-.Bd -ragged -offset indent
-.Fn RB_HEAD HEADNAME TYPE
-.Va head
-=
-.Fn RB_INITIALIZER &head ;
+.Bd -literal -offset indent
+RB_HEAD(HEADNAME, TYPE) head = RB_INITIALIZER(&head);
 .Ed
 .Pp
 The
@@ -422,6 +414,11 @@ The
 macro inserts the new element
 .Fa elm
 into the tree.
+Upon success,
+.Va NULL
+is returned.
+If a matching element already exists in the tree, the insertion is
+aborted, and a pointer to the existing element is returned.
 .Pp
 The
 .Fn RB_REMOVE
@@ -429,16 +426,24 @@ macro removes the element
 .Fa elm
 from the tree pointed by
 .Fa head .
+.Fn RB_REMOVE
+returns
+.Fa elm .
 .Pp
 The
 .Fn RB_FIND
 and
 .Fn RB_NFIND
 macros can be used to find a particular element in the tree.
+.Fn RB_FIND
+finds the node with the same key as
+.Fa elm .
+.Fn RB_NFIND
+finds the first node greater than or equal to the search key.
 .Bd -literal -offset indent
 struct TYPE find, *res;
 find.key = 30;
-res = RB_FIND(NAME, head, &find);
+res = RB_FIND(NAME, &head, &find);
 .Ed
 .Pp
 The
@@ -449,26 +454,119 @@ The
 and
 .Fn RB_PREV
 macros can be used to traverse the tree:
-.Pp
-.Dl "for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np))"
+.Bd -literal -offset indent
+for (np = RB_MIN(NAME, &head); np != NULL; np = RB_NEXT(NAME, &head, np))
+.Ed
 .Pp
 Or, for simplicity, one can use the
 .Fn RB_FOREACH
 or
 .Fn RB_FOREACH_REVERSE
-macro:
-.Bd -ragged -offset indent
-.Fn RB_FOREACH np NAME head
+macros:
+.Bd -literal -offset indent
+RB_FOREACH(np, NAME, &head)
 .Ed
 .Pp
+The macros
+.Fn RB_FOREACH_SAFE
+and
+.Fn RB_FOREACH_REVERSE_SAFE
+traverse the tree referenced by head
+in a forward or reverse direction respectively,
+assigning each element in turn to np.
+However, unlike their unsafe counterparts,
+they permit both the removal of np
+as well as freeing it from within the loop safely
+without interfering with the traversal.
+.Pp
 The
 .Fn RB_EMPTY
 macro should be used to check whether a red-black tree is empty.
+.Sh EXAMPLES
+The following example demonstrates how to declare a red-black tree
+holding integers.
+Values are inserted into it and the contents of the tree are printed
+in order.
+Lastly, the internal structure of the tree is printed.
+.Bd -literal -offset 3n
+#include <sys/tree.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+struct node {
+	RB_ENTRY(node) entry;
+	int i;
+};
+
+int	intcmp(struct node *, struct node *);
+void	print_tree(struct node *);
+
+int
+intcmp(struct node *e1, struct node *e2)
+{
+	return (e1->i < e2->i ? -1 : e1->i > e2->i);
+}
+
+RB_HEAD(inttree, node) head = RB_INITIALIZER(&head);
+RB_PROTOTYPE(inttree, node, entry, intcmp)
+RB_GENERATE(inttree, node, entry, intcmp)
+
+int testdata[] = {
+	20, 16, 17, 13, 3, 6, 1, 8, 2, 4, 10, 19, 5, 9, 12, 15, 18,
+	7, 11, 14
+};
+
+void
+print_tree(struct node *n)
+{
+	struct node *left, *right;
+
+	if (n == NULL) {
+		printf("nil");
+		return;
+	}
+	left = RB_LEFT(n, entry);
+	right = RB_RIGHT(n, entry);
+	if (left == NULL && right == NULL)
+		printf("%d", n->i);
+	else {
+		printf("%d(", n->i);
+		print_tree(left);
+		printf(",");
+		print_tree(right);
+		printf(")");
+	}
+}
+
+int
+main(void)
+{
+	int i;
+	struct node *n;
+
+	for (i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
+		if ((n = malloc(sizeof(struct node))) == NULL)
+			err(1, NULL);
+		n->i = testdata[i];
+		RB_INSERT(inttree, &head, n);
+	}
+
+	RB_FOREACH(n, inttree, &head) {
+		printf("%d\en", n->i);
+	}
+	print_tree(RB_ROOT(&head));
+	printf("\en");
+	return (0);
+}
+.Ed
+.Sh SEE ALSO
+.Xr queue 3bsd
 .Sh NOTES
 Trying to free a tree in the following way is a common error:
 .Bd -literal -offset indent
-SPLAY_FOREACH(var, NAME, head) {
-	SPLAY_REMOVE(NAME, head, var);
+SPLAY_FOREACH(var, NAME, &head) {
+	SPLAY_REMOVE(NAME, &head, var);
 	free(var);
 }
 free(head);
@@ -476,36 +574,17 @@ free(head);
 .Pp
 Since
 .Va var
-is freed, the
+is free'd, the
 .Fn FOREACH
 macro refers to a pointer that may have been reallocated already.
 Proper code needs a second variable.
 .Bd -literal -offset indent
-for (var = SPLAY_MIN(NAME, head); var != NULL; var = nxt) {
-	nxt = SPLAY_NEXT(NAME, head, var);
-	SPLAY_REMOVE(NAME, head, var);
+for (var = SPLAY_MIN(NAME, &head); var != NULL; var = nxt) {
+	nxt = SPLAY_NEXT(NAME, &head, var);
+	SPLAY_REMOVE(NAME, &head, var);
 	free(var);
 }
 .Ed
-.Pp
-Both
-.Fn RB_INSERT
-and
-.Fn SPLAY_INSERT
-return
-.Dv NULL
-if the element was inserted in the tree successfully, otherwise they
-return a pointer to the element with the colliding key.
-.Pp
-Accordingly,
-.Fn RB_REMOVE
-and
-.Fn SPLAY_REMOVE
-return the pointer to the removed element otherwise they return
-.Dv NULL
-to indicate an error.
-.Sh SEE ALSO
-.Xr queue 3bsd
 .Sh AUTHORS
 The author of the tree macros is
 .An Niels Provos .
commit 48107fc8c4aa6dd6bff7e209003677d5ec3e49ea
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Nov 28 23:19:16 2021 +0100

    build: Clarify link-time warnings
    
    Mention the involved function instead of stating an implicit "this
    function". Mention libbsd when proposing using an alternative libmd
    to make the context clear.

diff --git a/src/fgetln.c b/src/fgetln.c
index 502eb6f..b3b0a4b 100644
--- a/src/fgetln.c
+++ b/src/fgetln.c
@@ -76,7 +76,7 @@ fgetln(FILE *stream, size_t *len)
 	}
 }
 libbsd_link_warning(fgetln,
-                    "This function cannot be safely ported, use getline(3) "
+                    "The fgetln() function cannot be safely ported, use getline(3) "
                     "instead, as it is supported by GNU and POSIX.1-2008.");
 #else
 #error "Function fgetln() needs to be ported."
diff --git a/src/fgetwln.c b/src/fgetwln.c
index e6a0a17..f2ea094 100644
--- a/src/fgetwln.c
+++ b/src/fgetwln.c
@@ -88,5 +88,5 @@ fgetwln(FILE *stream, size_t *lenp)
 	return wused ? fb->wbuf : NULL;
 }
 libbsd_link_warning(fgetwln,
-                    "This function cannot be safely ported, use fgetwc(3) "
+                    "The fgetwln() function cannot be safely ported, use fgetwc(3) "
                     "instead, as it is supported by C99 and POSIX.1-2001.");
diff --git a/src/md5.c b/src/md5.c
index 1053fcd..ef4df33 100644
--- a/src/md5.c
+++ b/src/md5.c
@@ -35,7 +35,8 @@ libbsd_MD5Init(MD5_CTX *context)
 	MD5Init(context);
 }
 libbsd_link_warning(MD5Init,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5Init() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5Init, libbsd_MD5Init, LIBBSD_0.0);
 
 void
@@ -44,7 +45,8 @@ libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
 	MD5Update(context, data, len);
 }
 libbsd_link_warning(MD5Update,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5Update() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5Update, libbsd_MD5Update, LIBBSD_0.0);
 
 void
@@ -53,7 +55,8 @@ libbsd_MD5Pad(MD5_CTX *context)
 	MD5Pad(context);
 }
 libbsd_link_warning(MD5Pad,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5Pad() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5Pad, libbsd_MD5Pad, LIBBSD_0.0);
 
 void
@@ -62,7 +65,8 @@ libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
 	MD5Final(digest, context);
 }
 libbsd_link_warning(MD5Final,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5Final() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5Final, libbsd_MD5Final, LIBBSD_0.0);
 
 void
@@ -71,7 +75,8 @@ libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
 	MD5Transform(state, block);
 }
 libbsd_link_warning(MD5Transform,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5Transform() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5Transform, libbsd_MD5Transform, LIBBSD_0.0);
 
 char *
@@ -80,7 +85,8 @@ libbsd_MD5End(MD5_CTX *context, char *buf)
 	return MD5End(context, buf);
 }
 libbsd_link_warning(MD5End,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5End() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5End, libbsd_MD5End, LIBBSD_0.0);
 
 char *
@@ -89,7 +95,8 @@ libbsd_MD5File(const char *filename, char *buf)
 	return MD5File(filename, buf);
 }
 libbsd_link_warning(MD5File,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5File() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5File, libbsd_MD5File, LIBBSD_0.0);
 
 char *
@@ -98,7 +105,8 @@ libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
 	return MD5FileChunk(filename, buf, offset, length);
 }
 libbsd_link_warning(MD5FileChunk,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5FileChunk() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5FileChunk, libbsd_MD5FileChunk, LIBBSD_0.0);
 
 char *
@@ -107,5 +115,6 @@ libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
 	return MD5Data(data, len, buf);
 }
 libbsd_link_warning(MD5Data,
-                    "This function is a deprecated wrapper, use libmd instead.");
+                    "The MD5Data() function in libbsd is a deprecated wrapper, "
+                    "use libmd instead.");
 libbsd_symver_weak(MD5Data, libbsd_MD5Data, LIBBSD_0.0);
commit e7cf8c5785b14fc8fbd37bb665a5f9a4f28c7888
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Nov 28 22:44:08 2021 +0100

    Switch md5 compatibility logic back to direct linking
    
    When using the recent dlsym() based wrapper, we are not requiring any
    symbol from libmd, as we resolve those dynamically at run-time. We were
    ending up linking against libmd because in another part of the code we
    require (depending on the architecture) the SHA512 functions for the
    getentropy() local implementation. But that function might be provided
    by the system libc on some systems, which means we end up not linking
    against libmd at all.
    
    To solve this we go back to the previous simpler solution of linking
    directly, which had the main drawback of then making programs fail to
    link when not specifying -lmd (on platforms that need it). And then
    switch the .so link point from a symlink to a linker script, so that we
    can inject the -lmd library as-needed. This is similar to what glibc is
    doing.
    
    Fixes: commit 31f034e3862debda8615a449b1c11c4d6920dcc7

diff --git a/.gitignore b/.gitignore
index 460667b..4018a03 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,5 +20,6 @@ autom4te.cache/
 build-aux/
 configure
 config.*
+format.ld
 libtool
 stamp-h1
diff --git a/configure.ac b/configure.ac
index f40b1af..f0ea291 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,16 +101,10 @@ AM_CONDITIONAL([HAVE_LIBTESTU01],
                [test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
 
 saved_LIBS="$LIBS"
-AC_SEARCH_LIBS([dlsym], [dl], [
-  AS_IF([test "x$ac_cv_search_dlsym" != "xnone required"], [
-    LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_dlsym"
-  ])
-], [
-  AC_MSG_ERROR([cannot find required dlsym function])
-])
 AC_SEARCH_LIBS([MD5Update], [md], [
   AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
     MD5_LIBS="$MD5_LIBS $ac_cv_search_MD5Update"
+    need_transparent_libmd=yes
   ])
 ], [
   AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
@@ -124,6 +118,9 @@ AC_SEARCH_LIBS([SHA512Update], [md], [
 ])
 LIBS="$saved_LIBS"
 
+AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD],
+               [test "x$need_transparent_libmd" = "xyes"])
+
 is_windows=no
 AS_CASE([$host_os],
   [*-gnu*], [
diff --git a/src/Makefile.am b/src/Makefile.am
index d3f0162..2aa5f5b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,6 +25,7 @@ libbsd_la_included_sources = \
 	getentropy_win.c \
 	$(nil)
 
+CLEANFILES =
 EXTRA_DIST = \
 	libbsd.map \
 	libbsd.pc.in \
@@ -125,22 +126,51 @@ libbsd_la_SOURCES += \
 	$(nil)
 endif
 
+if NEED_TRANSPARENT_LIBMD
+CLEANFILES += \
+	format.ld \
+	# EOL
+endif
+
 libbsd_ctor_a_SOURCES = \
 	setproctitle_ctor.c \
 	$(nil)
 
+if NEED_TRANSPARENT_LIBMD
+TRANSPARENT_LIBMD_DEPENDS = format.ld
+
+format.ld:
+	$(CC) -shared -nostdlib -nostartfiles -x assembler /dev/null -o $@.so
+	objdump -f $@.so | sed -n 's/.*file format \(.*\)/OUTPUT_FORMAT(\1)/;T;p' > $@
+	rm -f $@.so
+endif
+
 runtimelibdir = $(libdir)
 
-install-exec-hook:
+install-exec-hook: $(TRANSPARENT_LIBMD_DEPENDS)
 	if [ "$(libdir)" != "$(runtimelibdir)" ]; then \
 		$(MKDIR_P) $(DESTDIR)$(runtimelibdir); \
 		mv $(DESTDIR)$(libdir)/libbsd*.so.* \
 		   $(DESTDIR)$(runtimelibdir)/; \
+	fi
+if NEED_TRANSPARENT_LIBMD
+# The "GNU ld script" magic is required so that GNU ldconfig does not complain
+# about an unknown format file.
+	soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \
+	$(RM) $(DESTDIR)$(libdir)/libbsd.so; \
+	(echo '/* GNU ld script'; \
+	 echo ' * The MD5 functions are provided by the libmd library. */'; \
+	 cat format.ld; \
+	 echo "GROUP($(runtimelibdir)/$$soname AS_NEEDED($(MD5_LIBS)))"; \
+	)>$(DESTDIR)$(libdir)/libbsd.so
+else
+	if [ "$(libdir)" != "$(runtimelibdir)" ]; then \
 		soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \
 		sorelprefix=`echo $(libdir) | $(SED) -r -e 's:(^/)?[^/]+:..:g'`; \
 		ln -sf $$sorelprefix$(runtimelibdir)/$$soname \
 		       $(DESTDIR)$(libdir)/libbsd.so; \
 	fi
+endif
 
 uninstall-hook:
 	rm -f $(DESTDIR)$(runtimelibdir)/libbsd*.so*
diff --git a/src/md5.c b/src/md5.c
index 00769aa..1053fcd 100644
--- a/src/md5.c
+++ b/src/md5.c
@@ -24,119 +24,88 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stddef.h>
-#include <stdlib.h>
-#include <dlfcn.h>
 #include <md5.h>
 #include "local-link.h"
 
-static void (*libmd_MD5Init)(MD5_CTX *);
-static void (*libmd_MD5Update)(MD5_CTX *, const uint8_t *, size_t);
-static void (*libmd_MD5Pad)(MD5_CTX *);
-static void (*libmd_MD5Final)(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *);
-static void (*libmd_MD5Transform)(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH]);
-static char *(*libmd_MD5End)(MD5_CTX *, char *);
-static char *(*libmd_MD5File)(const char *, char *);
-static char *(*libmd_MD5FileChunk)(const char *, char *, off_t, off_t);
-static char *(*libmd_MD5Data)(const uint8_t *, size_t, char *);
-
-static void *
-libmd_loader(const char *symbol)
-{
-	void *func;
-
-	func = dlsym(RTLD_NEXT, symbol);
-	if (func == NULL) {
-		fprintf(stderr,
-		        "libbsd: cannot find wrapped symbol %s in libc or libmd\n",
-		        symbol);
-		abort();
-	}
-
-	return func;
-}
-
-#define libmd_wrapper(symbol) \
-	if (libmd_ ## symbol == NULL) \
-		libmd_ ## symbol = libmd_loader(#symbol)
+#pragma GCC diagnostic ignored "-Wmissing-prototypes"
 
 void
-MD5Init(MD5_CTX *context)
+libbsd_MD5Init(MD5_CTX *context)
 {
-	libmd_wrapper(MD5Init);
-	libmd_MD5Init(context);
+	MD5Init(context);
 }
 libbsd_link_warning(MD5Init,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5Init, libbsd_MD5Init, LIBBSD_0.0);
 
 void
-MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
+libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
 {
-	libmd_wrapper(MD5Update);
-	libmd_MD5Update(context, data, len);
+	MD5Update(context, data, len);
 }
 libbsd_link_warning(MD5Update,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5Update, libbsd_MD5Update, LIBBSD_0.0);
 
 void
-MD5Pad(MD5_CTX *context)
+libbsd_MD5Pad(MD5_CTX *context)
 {
-	libmd_wrapper(MD5Pad);
-	libmd_MD5Pad(context);
+	MD5Pad(context);
 }
 libbsd_link_warning(MD5Pad,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5Pad, libbsd_MD5Pad, LIBBSD_0.0);
 
 void
-MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
+libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
 {
-	libmd_wrapper(MD5Final);
-	libmd_MD5Final(digest, context);
+	MD5Final(digest, context);
 }
 libbsd_link_warning(MD5Final,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5Final, libbsd_MD5Final, LIBBSD_0.0);
 
 void
-MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
+libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
 {
-	libmd_wrapper(MD5Transform);
-	libmd_MD5Transform(state, block);
+	MD5Transform(state, block);
 }
 libbsd_link_warning(MD5Transform,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5Transform, libbsd_MD5Transform, LIBBSD_0.0);
 
 char *
-MD5End(MD5_CTX *context, char *buf)
+libbsd_MD5End(MD5_CTX *context, char *buf)
 {
-	libmd_wrapper(MD5End);
-	return libmd_MD5End(context, buf);
+	return MD5End(context, buf);
 }
 libbsd_link_warning(MD5End,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5End, libbsd_MD5End, LIBBSD_0.0);
 
 char *
-MD5File(const char *filename, char *buf)
+libbsd_MD5File(const char *filename, char *buf)
 {
-	libmd_wrapper(MD5File);
 	return MD5File(filename, buf);
 }
 libbsd_link_warning(MD5File,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5File, libbsd_MD5File, LIBBSD_0.0);
 
 char *
-MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
+libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
 {
-	libmd_wrapper(MD5FileChunk);
-	return libmd_MD5FileChunk(filename, buf, offset, length);
+	return MD5FileChunk(filename, buf, offset, length);
 }
 libbsd_link_warning(MD5FileChunk,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5FileChunk, libbsd_MD5FileChunk, LIBBSD_0.0);
 
 char *
-MD5Data(const uint8_t *data, size_t len, char *buf)
+libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
 {
-	libmd_wrapper(MD5Data);
-	return libmd_MD5Data(data, len, buf);
+	return MD5Data(data, len, buf);
 }
 libbsd_link_warning(MD5Data,
                     "This function is a deprecated wrapper, use libmd instead.");
+libbsd_symver_weak(MD5Data, libbsd_MD5Data, LIBBSD_0.0);
diff --git a/test/Makefile.am b/test/Makefile.am
index de80b12..33d8aea 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -69,6 +69,11 @@ proctitle_LDFLAGS = \
 check_PROGRAMS += proctitle
 endif
 
+if NEED_TRANSPARENT_LIBMD
+# On the installed system this is handled via the ld script.
+md5_LDADD = $(LDADD) $(MD5_LIBS)
+endif
+
 fgetln_SOURCES = test-stream.c test-stream.h fgetln.c
 fgetln_CFLAGS = -Wno-deprecated-declarations
 fparseln_SOURCES = test-stream.c test-stream.h fparseln.c
commit 25d35625ebd8e41756751cbb069dd607fc9fc49f
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Nov 28 22:40:58 2021 +0100

    build: Split libmd dependency due to MD5 functions from SHA requirements
    
    To be able to rework the md5 deprecation logic, we need to detangle when
    we depend on libmd due to requiring MD5 functions, which might be
    otherwise provided by libc, or when we require SHA functions for the
    internal getentropy() implementation.

diff --git a/configure.ac b/configure.ac
index 806b7d3..f40b1af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,7 +110,7 @@ AC_SEARCH_LIBS([dlsym], [dl], [
 ])
 AC_SEARCH_LIBS([MD5Update], [md], [
   AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
-    LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_MD5Update"
+    MD5_LIBS="$MD5_LIBS $ac_cv_search_MD5Update"
   ])
 ], [
   AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
@@ -250,6 +250,7 @@ AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
                 pstat_getproc sysconf])
 AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
 
+AC_SUBST([MD5_LIBS])
 AC_SUBST([LIBBSD_LIBS])
 
 AC_CONFIG_FILES([
diff --git a/src/Makefile.am b/src/Makefile.am
index fe9d1e6..d3f0162 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,6 +52,7 @@ libbsd_la_DEPENDENCIES = \
 	$(libbsd_la_included_sources) \
 	libbsd.map
 libbsd_la_LIBADD = \
+	$(MD5_LIBS) \
 	$(LIBBSD_LIBS) \
 	$(nil)
 libbsd_la_LDFLAGS = \
diff --git a/src/libbsd-overlay.pc.in b/src/libbsd-overlay.pc.in
index 01b7ea5..0455f22 100644
--- a/src/libbsd-overlay.pc.in
+++ b/src/libbsd-overlay.pc.in
@@ -8,5 +8,5 @@ Description: Utility functions from BSD systems (overlay)
 Version: @VERSION@
 URL: https://libbsd.freedesktop.org/
 Libs: -L${libdir} -lbsd
-Libs.private: @LIBBSD_LIBS@
+Libs.private: @LIBBSD_LIBS@ @MD5_LIBS@
 Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY
diff --git a/src/libbsd.pc.in b/src/libbsd.pc.in
index 2c0ac17..4bca715 100644
--- a/src/libbsd.pc.in
+++ b/src/libbsd.pc.in
@@ -8,5 +8,5 @@ Description: Utility functions from BSD systems
 Version: @VERSION@
 URL: https://libbsd.freedesktop.org/
 Libs: -L${libdir} -lbsd
-Libs.private: @LIBBSD_LIBS@
+Libs.private: @LIBBSD_LIBS@ @MD5_LIBS@
 Cflags: -I${includedir}
commit 500b3080a2fd27dcd14113235e05ca003ce23190
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Nov 28 22:34:59 2021 +0100

    build: Add new libbsd_symver_weak() macro
    
    We will use it for the reworked md5 deprecation logic.

diff --git a/src/local-link.h b/src/local-link.h
index ebc197f..6782d9a 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -42,18 +42,29 @@
 #define libbsd_symver_variant(alias, symbol, version) \
 	extern __typeof__(symbol) symbol \
 		__attribute__((__symver__(#alias "@" #version)))
+
+#define libbsd_symver_weak(alias, symbol, version) \
+	extern __typeof__(symbol) symbol \
+		__attribute__((__symver__(#alias "@" #version), __weak__))
 #  else
 #define libbsd_symver_default(alias, symbol, version) \
 	__asm__(".symver " #symbol "," #alias "@@" #version)
 
 #define libbsd_symver_variant(alias, symbol, version) \
 	__asm__(".symver " #symbol "," #alias "@" #version)
+
+#define libbsd_symver_weak(alias, symbol, version) \
+	libbsd_symver_variant(alias, symbol, version); \
+	extern __typeof__(symbol) alias \
+		__attribute__((__weak__))
 #  endif
 #else
 #define libbsd_symver_default(alias, symbol, version) \
 	extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
 
 #define libbsd_symver_variant(alias, symbol, version)
+
+#define libbsd_symver_weak(alias, symbol, version)
 #endif
 
 #endif


More information about the libbsd mailing list