libbsd: Branch 'main' - 5 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Feb 18 13:08:47 UTC 2024


 .gitignore         |    1 
 configure.ac       |   14 +++++++--
 man/Makefile.am    |   16 ++++++++---
 man/strtoi.3bsd    |   22 +++++++++------
 man/strtou.3bsd    |   22 +++++++++------
 src/Makefile.am    |   24 ++++++++++++++--
 src/err.c          |   50 -----------------------------------
 src/errc.c         |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/libbsd.map.in  |    2 +
 src/local-link.h   |   26 +++++++++---------
 src/md5.c          |   18 ++++++------
 src/setproctitle.c |    6 ++--
 src/strtoi.c       |   20 +++++++-------
 src/strtonum.c     |   28 ++++++++++++++-----
 src/strtou.c       |   18 ++++++------
 src/unvis.c        |    4 +-
 src/vis.c          |    4 +-
 17 files changed, 219 insertions(+), 131 deletions(-)

New commits:
commit 9fab225f2676c1a230bb9ea71a548e3b9796a28d
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Feb 17 05:25:01 2024 +0100

    Split errc family of functions from err ones
    
    On most systems the err family of functions is already present, but are
    missing the errc family of functions, which are also present on some
    other systems. Splitting them into separate files will make it easer to
    conditionally include one or the other.

diff --git a/configure.ac b/configure.ac
index e704168..7878743 100644
--- a/configure.ac
+++ b/configure.ac
@@ -257,6 +257,8 @@ AC_CHECK_FUNCS([\
 
 need_arc4random=yes
 need_bsd_getopt=yes
+need_err=yes
+need_errc=yes
 need_progname=yes
 need_md5=yes
 need_nlist=yes
@@ -271,6 +273,7 @@ AS_CASE([$host_os],
     # On glibc >= 2.38, strlcpy() and strlcat() got added,
     # so these could then be dropped on the next SOVERSION bump.
     #need_strl=no
+    need_err=no
   ],
   [*-musl*], [
     # On musl >= 0.5.0, strlcpy() and strlcat() were already implemented,
@@ -279,6 +282,7 @@ AS_CASE([$host_os],
     # On musl >= 0.9.7, optreset got implemented, so bsd_getopt() can then
     # be dropped on the next SOVERSION bump.
     #need_bsd_getopt=no
+    need_err=no
     # On musl >= 1.1.19, fopencookie() got implemented, and because we were
     # checking for its presence to decide whether to build funopen(), it got
     # included in builds even when previously it had not been included, which
@@ -292,6 +296,8 @@ AS_CASE([$host_os],
     # there, so we can avoid providing these with no ABI breakage.
     need_arc4random=no
     need_bsd_getopt=no
+    need_err=no
+    need_errc=no
     need_progname=no
     need_transparent_libmd=no
     need_md5=no
@@ -310,6 +316,8 @@ AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"])
 
 AM_CONDITIONAL([NEED_ARC4RANDOM], [test "x$need_arc4random" = "xyes"])
 AM_CONDITIONAL([NEED_BSD_GETOPT], [test "x$need_bsd_getopt" = "xyes"])
+AM_CONDITIONAL([NEED_ERR], [test "x$need_err" = "xyes"])
+AM_CONDITIONAL([NEED_ERRC], [test "x$need_errc" = "xyes"])
 AM_CONDITIONAL([NEED_PROGNAME], [test "x$need_progname" = "xyes"])
 AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD], [test "x$need_transparent_libmd" = "xyes"])
 AM_CONDITIONAL([NEED_MD5], [test "x$need_md5" = "xyes"])
diff --git a/man/Makefile.am b/man/Makefile.am
index 1223557..b878fef 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -168,7 +168,6 @@ dist_man_MANS = \
 	byteorder.3bsd \
 	closefrom.3bsd \
 	dehumanize_number.3bsd \
-	errc.3bsd \
 	expand_number.3bsd \
 	explicit_bzero.3bsd \
 	fgetln.3bsd \
@@ -238,6 +237,12 @@ dist_man_MANS = \
 	vis.3bsd \
 	# EOL
 
+if NEED_ERRC
+dist_man_MANS += \
+	errc.3bsd \
+	# EOL
+endif
+
 if NEED_PROGNAME
 dist_man_MANS += \
 	getprogname.3bsd \
diff --git a/src/Makefile.am b/src/Makefile.am
index 1c350b8..1877ad6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -78,7 +78,6 @@ endif
 libbsd_la_SOURCES = \
 	closefrom.c \
 	dehumanize_number.c \
-	err.c \
 	expand_number.c \
 	explicit_bzero.c \
 	fgetln.c \
@@ -114,6 +113,18 @@ libbsd_la_SOURCES = \
 	vis.c \
 	# EOL
 
+if NEED_ERR
+libbsd_la_SOURCES += \
+	err.c \
+	# EOL
+endif
+
+if NEED_ERRC
+libbsd_la_SOURCES += \
+	errc.c \
+	# EOL
+endif
+
 if NEED_PROGNAME
 libbsd_la_SOURCES += \
 	progname.c \
diff --git a/src/err.c b/src/err.c
index 8f09972..44359e8 100644
--- a/src/err.c
+++ b/src/err.c
@@ -1,6 +1,5 @@
 /*
- * Copyright © 2006 Robert Millan
- * Copyright © 2011, 2019 Guillem Jover <guillem at hadrons.org>
+ * Copyright © 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,58 +25,12 @@
  */
 
 #include <err.h>
-#ifdef LIBBSD_NEED_ERR_H_FUNCS
 #include <errno.h>
-#endif
 #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, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-	vwarnc(code, format, ap);
-	va_end(ap);
-}
-
-void
-verrc(int status, 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));
-	exit(status);
-}
-
-void
-errc(int status, int code, const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-	verrc(status, code, format, ap);
-	va_end(ap);
-}
-
-#ifdef LIBBSD_NEED_ERR_H_FUNCS
 void
 vwarn(const char *format, va_list ap)
 {
@@ -148,4 +101,3 @@ errx(int eval, const char *format, ...)
 	verrx(eval, format, ap);
 	va_end(ap);
 }
-#endif
diff --git a/src/errc.c b/src/errc.c
new file mode 100644
index 0000000..45f1b61
--- /dev/null
+++ b/src/errc.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2006 Robert Millan
+ * 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <err.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, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	vwarnc(code, format, ap);
+	va_end(ap);
+}
+
+void
+verrc(int status, 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));
+	exit(status);
+}
+
+void
+errc(int status, int code, const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	verrc(status, code, format, ap);
+	va_end(ap);
+}
commit 461f10ac579f4e997db7493c61b2601c269bef1d
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sat Feb 17 03:07:58 2024 +0100

    Sync strtoi()/strtou() implementations from NetBSD
    
    These contain the fixes to the error handling logic.
    
    In NetBSD the manual page for strtou.3 is generated from the strtoi.3
    manual page applying some substitutions, the problem is that the
    cross-references are then lost. We will still keep them separate.
    
    Reported-by: Alejandro Colomar <alx at kernel.org>

diff --git a/man/strtoi.3bsd b/man/strtoi.3bsd
index 15102da..5988361 100644
--- a/man/strtoi.3bsd
+++ b/man/strtoi.3bsd
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoi.3,v 1.7 2017/07/03 21:32:50 wiz Exp $
+.\"	$NetBSD: strtoi.3,v 1.10 2024/02/10 18:43:51 andvar Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -36,12 +36,12 @@
 .\" Created by Kamil Rytarowski, based on ID:
 .\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
 .\"
-.Dd November 13, 2015
+.Dd January 20, 2024
 .Dt strtoi 3bsd
 .Os
 .Sh NAME
 .Nm strtoi
-.Nd convert string value to an intmax_t integer
+.Nd convert a 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]
@@ -63,8 +63,7 @@ for include usage.)
 .Sh DESCRIPTION
 The
 .Fn strtoi
-function
-converts the string in
+function converts the string in
 .Fa nptr
 to an
 .Ft intmax_t
@@ -77,7 +76,7 @@ and ensures that the result is always in the range [
 .Fa lo ..
 .Fa hi
 ].
-In adddition it always places
+In addition it always places
 .Dv 0
 on success or a conversion status in the
 .Fa rstatus
@@ -122,10 +121,11 @@ is taken as 10 (decimal) unless the next character is
 .Ql 0 ,
 in which case it is taken as 8 (octal).
 .Pp
-The remainder of the string is converted to a
+The remainder of the string is converted to an
 .Em intmax_t
 value in the obvious manner,
-stopping at the first character which is not a valid digit
+stopping at the end of the string
+or at the first character which is not a valid digit
 in the given base.
 (In bases above 10, the letter
 .Ql A
@@ -206,6 +206,12 @@ or the range given was invalid, i.e.
 >
 .Fa hi .
 .El
+.Pp
+The range check is more important than the unconverted characters check,
+and it is performed first.
+If a program needs to know if there were unconverted characters when an
+out of range number has been provided, it needs to supply and test
+.Fa endptr.
 .Sh SEE ALSO
 .Xr atof 3 ,
 .Xr atoi 3 ,
diff --git a/man/strtou.3bsd b/man/strtou.3bsd
index d7e02eb..0291568 100644
--- a/man/strtou.3bsd
+++ b/man/strtou.3bsd
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtou.3,v 1.7 2017/07/03 21:32:50 wiz Exp $
+.\"	$NetBSD: strtou.3,v 1.8 2024/01/20 16:13:39 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -36,12 +36,12 @@
 .\" Created by Kamil Rytarowski, based on ID:
 .\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
 .\"
-.Dd November 13, 2015
+.Dd January 20, 2024
 .Dt strtou 3bsd
 .Os
 .Sh NAME
 .Nm strtou
-.Nd convert a string to an uintmax_t integer
+.Nd convert a string value 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]
@@ -76,7 +76,7 @@ and ensures that the result is always in the range [
 .Fa lo ..
 .Fa hi
 ].
-In adddition it always places
+In addition it always places
 .Dv 0
 on success or a conversion status in the
 .Fa rstatus
@@ -125,7 +125,7 @@ The remainder of the string is converted to an
 .Em uintmax_t
 value in the obvious manner,
 stopping at the end of the string
-or at the first character that does not produce a valid digit
+or at the first character which is not a valid digit
 in the given base.
 (In bases above 10, the letter
 .Ql A
@@ -200,12 +200,18 @@ In this case,
 .Fa endptr
 points to the first unconverted character.
 .It Bq Er ERANGE
-The given string was out of range; the value converted has been clamped; or
-the range given was invalid, i.e.
+The given string was out of range; the value converted has been clamped;
+or the range given was invalid, i.e.
 .Fa lo
 >
 .Fa hi .
 .El
+.Pp
+The range check is more important than the unconverted characters check,
+and it is performed first.
+If a program needs to know if there were unconverted characters when an
+out of range number has been provided, it needs to supply and test
+.Fa endptr.
 .Sh SEE ALSO
 .Xr atof 3 ,
 .Xr atoi 3 ,
@@ -220,13 +226,13 @@ 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
 .Nx
 extension.
 .Sh HISTORY
+.ds doc-operating-system-NetBSD-7.0 7.0
 The
 .Fn strtou
 function first appeared in
diff --git a/src/strtoi.c b/src/strtoi.c
index 9e3771d..7a27ca7 100644
--- a/src/strtoi.c
+++ b/src/strtoi.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $	*/
+/*	$NetBSD: _strtoi.h,v 1.3 2024/01/20 16:13:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -32,7 +32,7 @@
  * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
  *
  * Created by Kamil Rytarowski, based on ID:
- * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joe…
+ * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp
  */
 
 #include <sys/cdefs.h>
@@ -73,25 +73,25 @@ strtoi(const char *__restrict nptr,
 	*rstatus = errno;
 	errno = serrno;
 
-	if (*rstatus == 0) {
-		/* No digits were found */
-		if (nptr == *endptr)
-			*rstatus = ECANCELED;
-		/* There are further characters after number */
-		else if (**endptr != '\0')
-			*rstatus = ENOTSUP;
-	}
+	/* No digits were found */
+	if (*rstatus == 0 && nptr == *endptr)
+		*rstatus = ECANCELED;
 
 	if (im < lo) {
 		if (*rstatus == 0)
 			*rstatus = ERANGE;
 		return lo;
 	}
+
 	if (im > hi) {
 		if (*rstatus == 0)
 			*rstatus = ERANGE;
 		return hi;
 	}
 
+	/* There are further characters after number */
+	if (*rstatus == 0 && **endptr != '\0')
+		*rstatus = ENOTSUP;
+
 	return im;
 }
diff --git a/src/strtonum.c b/src/strtonum.c
index 2fa0fcf..8d6faa1 100644
--- a/src/strtonum.c
+++ b/src/strtonum.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $	*/
+/*	$NetBSD: strtonum.c,v 1.7 2024/01/20 16:13:39 christos Exp $	*/
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -42,21 +42,33 @@ strtonum(const char *nptr, long long minval, long long maxval,
 	int e;
 	long long rv;
 	const char *resp;
+	char *eptr;
 
 	if (errstr == NULL)
 		errstr = &resp;
 
-	rv = (long long)strtoi(nptr, NULL, 10, minval, maxval, &e);
+	if (minval > maxval)
+		goto out;
 
-	if (e == 0) {
+	rv = (long long)strtoi(nptr, &eptr, 10, minval, maxval, &e);
+
+	switch (e) {
+	case 0:
 		*errstr = NULL;
 		return rv;
+	case ECANCELED:
+	case ENOTSUP:
+		goto out;
+	case ERANGE:
+		if (*eptr)
+			goto out;
+		*errstr = rv == maxval ? "too large" : "too small";
+		return 0;
+	default:
+		abort();
 	}
 
-	if (e == ERANGE)
-		*errstr = (rv == maxval ? "too large" : "too small");
-	else
-		*errstr = "invalid";
-
+out:
+	*errstr = "invalid";
 	return 0;
 }
diff --git a/src/strtou.c b/src/strtou.c
index 0e22a88..a87adcc 100644
--- a/src/strtou.c
+++ b/src/strtou.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $	*/
+/*	$NetBSD: _strtoi.h,v 1.3 2024/01/20 16:13:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -73,25 +73,25 @@ strtou(const char *__restrict nptr,
 	*rstatus = errno;
 	errno = serrno;
 
-	if (*rstatus == 0) {
-		/* No digits were found */
-		if (nptr == *endptr)
-			*rstatus = ECANCELED;
-		/* There are further characters after number */
-		else if (**endptr != '\0')
-			*rstatus = ENOTSUP;
-	}
+	/* No digits were found */
+	if (*rstatus == 0 && nptr == *endptr)
+		*rstatus = ECANCELED;
 
 	if (im < lo) {
 		if (*rstatus == 0)
 			*rstatus = ERANGE;
 		return lo;
 	}
+
 	if (im > hi) {
 		if (*rstatus == 0)
 			*rstatus = ERANGE;
 		return hi;
 	}
 
+	/* There are further characters after number */
+	if (*rstatus == 0 && **endptr != '\0')
+		*rstatus = ENOTSUP;
+
 	return im;
 }
commit f0501609764fe1e725c18e847c3904ed3a6544e0
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Feb 14 03:39:16 2024 +0100

    build: Swap symbol and alias arguments order in macros creating aliases
    
    The current order is rather confusing, pass the real symbol first
    and the alias we want to create next.

diff --git a/src/local-link.h b/src/local-link.h
index a05d5ed..d6bd77f 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -38,47 +38,47 @@
 #endif
 
 #if defined(__APPLE__)
-#define libbsd_strong_alias(alias, symbol) \
+#define libbsd_strong_alias(symbol, alias) \
 	__asm__(".globl _" #alias); \
 	__asm__(".set _" #alias ", _" #symbol); \
 	extern __typeof(symbol) alias
 #elif !defined(_MSC_VER)
-#define libbsd_strong_alias(alias, symbol) \
+#define libbsd_strong_alias(symbol, alias) \
 	extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
 #endif
 
 #ifdef __ELF__
 #  if __has_attribute(symver)
 /* The symver attribute is supported since gcc 10.x. */
-#define libbsd_symver_default(alias, symbol, version) \
+#define libbsd_symver_default(symbol, alias, version) \
 	extern __typeof__(symbol) symbol \
 		__attribute__((__symver__(#alias "@@" #version)))
-#define libbsd_symver_variant(alias, symbol, version) \
+#define libbsd_symver_variant(symbol, alias, version) \
 	extern __typeof__(symbol) symbol \
 		__attribute__((__symver__(#alias "@" #version)))
 
-#define libbsd_symver_weak(alias, symbol, version) \
+#define libbsd_symver_weak(symbol, alias, version) \
 	extern __typeof__(symbol) symbol \
 		__attribute__((__symver__(#alias "@" #version), __weak__))
 #  else
-#define libbsd_symver_default(alias, symbol, version) \
+#define libbsd_symver_default(symbol, alias, version) \
 	__asm__(".symver " #symbol "," #alias "@@" #version)
 
-#define libbsd_symver_variant(alias, symbol, version) \
+#define libbsd_symver_variant(symbol, alias, version) \
 	__asm__(".symver " #symbol "," #alias "@" #version)
 
-#define libbsd_symver_weak(alias, symbol, version) \
-	libbsd_symver_variant(alias, symbol, version); \
+#define libbsd_symver_weak(symbol, alias, version) \
+	libbsd_symver_variant(symbol, alias, version); \
 	extern __typeof__(symbol) alias \
 		__attribute__((__weak__))
 #  endif
 #else
-#define libbsd_symver_default(alias, symbol, version) \
-	libbsd_strong_alias(alias, symbol)
+#define libbsd_symver_default(symbol, alias, version) \
+	libbsd_strong_alias(symbol, alias)
 
-#define libbsd_symver_variant(alias, symbol, version)
+#define libbsd_symver_variant(symbol, alias, version)
 
-#define libbsd_symver_weak(alias, symbol, version)
+#define libbsd_symver_weak(symbol, alias, version)
 #endif
 
 #endif
diff --git a/src/md5.c b/src/md5.c
index ef4df33..289cba4 100644
--- a/src/md5.c
+++ b/src/md5.c
@@ -37,7 +37,7 @@ libbsd_MD5Init(MD5_CTX *context)
 libbsd_link_warning(MD5Init,
                     "The MD5Init() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5Init, libbsd_MD5Init, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5Init, MD5Init, LIBBSD_0.0);
 
 void
 libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
@@ -47,7 +47,7 @@ libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
 libbsd_link_warning(MD5Update,
                     "The MD5Update() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5Update, libbsd_MD5Update, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5Update, MD5Update, LIBBSD_0.0);
 
 void
 libbsd_MD5Pad(MD5_CTX *context)
@@ -57,7 +57,7 @@ libbsd_MD5Pad(MD5_CTX *context)
 libbsd_link_warning(MD5Pad,
                     "The MD5Pad() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5Pad, libbsd_MD5Pad, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5Pad, MD5Pad, LIBBSD_0.0);
 
 void
 libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
@@ -67,7 +67,7 @@ libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
 libbsd_link_warning(MD5Final,
                     "The MD5Final() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5Final, libbsd_MD5Final, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5Final, MD5Final, LIBBSD_0.0);
 
 void
 libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
@@ -77,7 +77,7 @@ libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
 libbsd_link_warning(MD5Transform,
                     "The MD5Transform() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5Transform, libbsd_MD5Transform, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5Transform, MD5Transform, LIBBSD_0.0);
 
 char *
 libbsd_MD5End(MD5_CTX *context, char *buf)
@@ -87,7 +87,7 @@ libbsd_MD5End(MD5_CTX *context, char *buf)
 libbsd_link_warning(MD5End,
                     "The MD5End() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5End, libbsd_MD5End, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5End, MD5End, LIBBSD_0.0);
 
 char *
 libbsd_MD5File(const char *filename, char *buf)
@@ -97,7 +97,7 @@ libbsd_MD5File(const char *filename, char *buf)
 libbsd_link_warning(MD5File,
                     "The MD5File() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5File, libbsd_MD5File, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5File, MD5File, LIBBSD_0.0);
 
 char *
 libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
@@ -107,7 +107,7 @@ libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
 libbsd_link_warning(MD5FileChunk,
                     "The MD5FileChunk() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5FileChunk, libbsd_MD5FileChunk, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5FileChunk, MD5FileChunk, LIBBSD_0.0);
 
 char *
 libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
@@ -117,4 +117,4 @@ libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
 libbsd_link_warning(MD5Data,
                     "The MD5Data() function in libbsd is a deprecated wrapper, "
                     "use libmd instead.");
-libbsd_symver_weak(MD5Data, libbsd_MD5Data, LIBBSD_0.0);
+libbsd_symver_weak(libbsd_MD5Data, MD5Data, LIBBSD_0.0);
diff --git a/src/setproctitle.c b/src/setproctitle.c
index d77d67f..06928e6 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -289,17 +289,17 @@ setproctitle_impl(const char *fmt, ...)
 		*++nul = '\0';
 	}
 }
-libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
+libbsd_symver_default(setproctitle_impl, setproctitle, 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
  * for code linking against that version, and change the default to use the
  * new version, so that new code depends on the implemented version. */
 #if defined(libbsd_strong_alias)
-libbsd_strong_alias(setproctitle_stub, setproctitle_impl);
+libbsd_strong_alias(setproctitle_impl, setproctitle_stub);
 #else
 void
 setproctitle_stub(const char *fmt, ...)
 	__attribute__((__alias__("setproctitle_impl")));
 #endif
-libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);
+libbsd_symver_variant(setproctitle_stub, setproctitle, LIBBSD_0.2);
diff --git a/src/unvis.c b/src/unvis.c
index 9c29f9e..378cee6 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -570,7 +570,7 @@ strnunvis_openbsd(char *dst, const char *src, size_t dlen)
 {
 	return strnunvisx(dst, dlen, src, 0);
 }
-libbsd_symver_default(strnunvis, strnunvis_openbsd, LIBBSD_0.2);
+libbsd_symver_default(strnunvis_openbsd, strnunvis, LIBBSD_0.2);
 
 int
 strnunvis_netbsd(char *, size_t, const char *);
@@ -579,4 +579,4 @@ strnunvis_netbsd(char *dst, size_t dlen, const char *src)
 {
 	return strnunvisx(dst, dlen, src, 0);
 }
-libbsd_symver_variant(strnunvis, strnunvis_netbsd, LIBBSD_0.9.1);
+libbsd_symver_variant(strnunvis_netbsd, strnunvis, LIBBSD_0.9.1);
diff --git a/src/vis.c b/src/vis.c
index 1a18a57..0dafa62 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -739,7 +739,7 @@ strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
 {
 	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
-libbsd_symver_default(strnvis, strnvis_openbsd, LIBBSD_0.2);
+libbsd_symver_default(strnvis_openbsd, strnvis, LIBBSD_0.2);
 
 int
 strnvis_netbsd(char *, size_t, const char *, int);
@@ -748,7 +748,7 @@ strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
 {
 	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
-libbsd_symver_variant(strnvis, strnvis_netbsd, LIBBSD_0.9.1);
+libbsd_symver_variant(strnvis_netbsd, strnvis, LIBBSD_0.9.1);
 
 int
 stravis(char **mbdstp, const char *mbsrc, int flags)
commit 19e06407eb365a2bedc9bdd29a83c1e1803e3f92
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Feb 11 19:35:05 2024 +0100

    build: Generate the map file from the configured ABI
    
    Some linkers require the map file definitions to contain only symbols
    that are present on the linked object, either in the map file or in the
    sym file we generate from the map file.
    
    This is preparatory work to be able to conditionally include symbols
    in the man and sym files depending on the ABI definitions.

diff --git a/.gitignore b/.gitignore
index 5c3a5ed..a6f6403 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@ ChangeLog
 *.gcda
 *.gcno
 *.sym
+*.map
 .dirstamp
 .deps/
 .libs/
diff --git a/src/Makefile.am b/src/Makefile.am
index 6f2325c..1c350b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,7 +28,7 @@ libbsd_la_included_sources = \
 
 CLEANFILES =
 EXTRA_DIST = \
-	libbsd.map \
+	libbsd.map.in \
 	libbsd.pc.in \
 	libbsd-ctor.pc.in \
 	libbsd-overlay.pc.in \
@@ -53,6 +53,7 @@ endif
 EXTRA_libbsd_la_DEPENDENCIES = \
 	$(libbsd_la_included_sources) \
 	libbsd.map \
+	libbsd.map.in \
 	# EOL
 libbsd_la_LIBADD = \
 	$(MD5_LIBS) \
@@ -64,7 +65,7 @@ libbsd_la_LDFLAGS = \
 	# EOL
 if HAVE_LINKER_VERSION_SCRIPT
 libbsd_la_LDFLAGS += \
-	-Wl,--version-script=$(srcdir)/libbsd.map \
+	-Wl,--version-script=libbsd.map \
 	# EOL
 else
 libbsd_la_LDFLAGS += \
@@ -194,12 +195,18 @@ endif
 
 DISTCLEANFILES = \
 	libbsd.sym \
+	libbsd.map \
 	# EOL
 
 libbsd_ctor_a_SOURCES = \
 	setproctitle_ctor.c \
 	# EOL
 
+# Generate the library map file with the pre-processor to selectively include
+# symbols depending on the host system, otherwise some linkers might fail.
+libbsd.map: libbsd.map.in
+	$(CPP) $(AM_CPPFLAGS) $(CPPFLAGS) -P - <$(srcdir)/libbsd.map.in >$@
+
 # Generate a simple libtool symbol export list to be used as a fallback if
 # there is no version script support.
 libbsd.sym: libbsd.map
diff --git a/src/libbsd.map b/src/libbsd.map.in
similarity index 99%
rename from src/libbsd.map
rename to src/libbsd.map.in
index 6c61235..06550ea 100644
--- a/src/libbsd.map
+++ b/src/libbsd.map.in
@@ -1,3 +1,5 @@
+#include "config.h"
+
 LIBBSD_0.0 {
   global:
     arc4random;
commit 10920c3084446703663ccc1aa4146999dcd61f78
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Feb 12 00:06:56 2024 +0100

    build: Make name_from_id man pages conditional instead of id_from_name
    
    The code is only making the name_from_id function conditional, and
    assumes id_from_name are always to be included, so we need to match
    the logic for the man page inclusion.

diff --git a/configure.ac b/configure.ac
index c3e6fbb..e704168 100644
--- a/configure.ac
+++ b/configure.ac
@@ -263,7 +263,7 @@ need_nlist=yes
 need_strl=yes
 need_wcsl=yes
 need_strmode=yes
-need_id_from_name=yes
+need_name_from_id=yes
 need_fpurge=yes
 need_funopen=yes
 AS_CASE([$host_os],
@@ -299,7 +299,7 @@ AS_CASE([$host_os],
     need_strl=no
     need_wcsl=no
     need_strmode=no
-    need_id_from_name=no
+    need_name_from_id=no
     need_fpurge=no
     # On macOS we do not have fopencookie(), and cannot implement it.
     need_funopen=no
@@ -317,7 +317,7 @@ AM_CONDITIONAL([NEED_NLIST], [test "x$need_nlist" = "xyes"])
 AM_CONDITIONAL([NEED_STRL], [test "x$need_strl" = "xyes"])
 AM_CONDITIONAL([NEED_WCSL], [test "x$need_wcsl" = "xyes"])
 AM_CONDITIONAL([NEED_STRMODE], [test "x$need_strmode" = "xyes"])
-AM_CONDITIONAL([NEED_ID_FROM_NAME], [test "x$need_id_from_name" = "xyes"])
+AM_CONDITIONAL([NEED_NAME_FROM_ID], [test "x$need_name_from_id" = "xyes"])
 AM_CONDITIONAL([NEED_FPURGE], [test "x$need_fpurge" = "xyes"])
 AM_CONDITIONAL([NEED_FUNOPEN], [test "x$need_funopen" = "xyes"])
 AS_IF([test "x$need_funopen" = "xno" && \
diff --git a/man/Makefile.am b/man/Makefile.am
index 14bea2b..1223557 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -180,7 +180,6 @@ dist_man_MANS = \
 	getbsize.3bsd \
 	getmode.3bsd \
 	getpeereid.3bsd \
-	group_from_gid.3bsd \
 	heapsort.3bsd \
 	humanize_number.3bsd \
 	le16dec.3bsd \
@@ -236,7 +235,6 @@ dist_man_MANS = \
 	timeval.3bsd \
 	tree.3bsd \
 	unvis.3bsd \
-	user_from_uid.3bsd \
 	vis.3bsd \
 	# EOL
 
@@ -279,11 +277,16 @@ dist_man_MANS += \
 	# EOL
 endif
 
-if NEED_ID_FROM_NAME
 dist_man_MANS += \
 	uid_from_user.3bsd \
 	gid_from_group.3bsd \
 	# EOL
+
+if NEED_NAME_FROM_ID
+dist_man_MANS += \
+	group_from_gid.3bsd \
+	user_from_uid.3bsd \
+	# EOL
 endif
 
 if NEED_FPURGE


More information about the libbsd mailing list