libbsd: Branch 'main' - 10 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Nov 27 05:40:37 UTC 2021


 .gitignore            |    1 -
 configure.ac          |   43 ++++++++++++++++++++++++++++++++++++++++---
 m4/.gitignore         |    2 ++
 m4/libbsd-compiler.m4 |   24 ++++++++++++++++++++++++
 man/Makefile.am       |    2 +-
 man/libbsd.7          |    3 ++-
 src/Makefile.am       |    2 +-
 src/explicit_bzero.c  |    5 ++++-
 src/local-link.h      |   12 ++++++++++++
 src/setproctitle.c    |    4 ++++
 src/unvis.c           |    4 ++++
 src/vis.c             |    4 ++++
 test/Makefile.am      |    1 +
 test/fgetln.c         |    8 ++++----
 test/fparseln.c       |    2 +-
 test/funopen.c        |    2 +-
 test/nlist.c          |   10 +++++-----
 test/test-stream.c    |    8 ++++++--
 test/test-stream.h    |    7 ++++++-
 19 files changed, 122 insertions(+), 22 deletions(-)

New commits:
commit 428be9e0302915525513bb757e10103dbff60d4e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Oct 7 23:08:42 2021 +0200

    man: Fix .Nx macro usage
    
    Its arguments are used as version numbers, so we need continue the
    content on the next line.

diff --git a/man/libbsd.7 b/man/libbsd.7
index cad9e7c..9710a13 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -160,7 +160,8 @@ functions and is now more widespread.
 Define
 .Dv LIBBSD_NETBSD_VIS
 to switch to the
-.Nx one now.
+.Nx
+one now.
 Define
 .Dv LIBBSD_OPENBSD_VIS
 to keep using the
commit c7a5d780ae58b6f7ae7d814fd5bc53cf1f58ee5f
Author: Alexander Miller <alex.miller at gmx.de>
Date:   Thu Sep 30 03:39:57 2021 +0200

    build: Allow building with -flto on gcc-10 and newer
    
    Global asm statements (like .symver directives) do not work reliably
    in gcc with link time optimization. Use the symver attribute introduced
    with gcc-10 to set symbol versions instead, if available.
    
    [guillem at hadrons.org:
     - Simplify by using __has_attribute fallback from <sys/cdefs.h>.
     - Coding style changes. ]
    
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/local-link.h b/src/local-link.h
index 55fd028..fd1949c 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -27,16 +27,28 @@
 #ifndef LIBBSD_LOCAL_LINK_H
 #define LIBBSD_LOCAL_LINK_H
 
+#include <sys/cdefs.h>
+
 #define libbsd_link_warning(symbol, msg) \
 	static const char libbsd_emit_link_warning_##symbol[] \
 		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg
 
 #ifdef __ELF__
+#  if __has_attribute(symver)
+/* The symver attribute is supported since gcc 10.x. */
+#define libbsd_symver_default(alias, symbol, version) \
+	extern __typeof(symbol) symbol \
+		__attribute((__symver__(#alias "@@" #version)))
+#define libbsd_symver_variant(alias, symbol, version) \
+	extern __typeof(symbol) symbol \
+		__attribute((__symver__(#alias "@" #version)))
+#  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)
+#  endif
 #else
 #define libbsd_symver_default(alias, symbol, version) \
 	extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
commit 1808d64b772cf03bac159210f8692125c9a84606
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Mar 1 05:14:10 2021 +0100

    test: Fix pipe_feed() to allow checking fprintf format strings
    
    Warned-by: gcc -W

diff --git a/test/fgetln.c b/test/fgetln.c
index d08fb3b..2eafa84 100644
--- a/test/fgetln.c
+++ b/test/fgetln.c
@@ -75,7 +75,7 @@ test_fgetln_single(void)
 	size_t len;
 	int i;
 
-	fp = pipe_feed("%s", (const void **)data_ascii, DATA_LINES);
+	fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_ascii, DATA_LINES);
 	for (i = 0; i < DATA_LINES; i++) {
 		char *str = fgetln(fp, &len);
 
@@ -102,7 +102,7 @@ test_fgetln_multi(void)
 		files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
 		files[i].lines[0] = str;
 		files[i].lines[1] = str;
-		files[i].fp = pipe_feed("%s", files[i].lines, LINE_COUNT);
+		files[i].fp = pipe_feed(PIPE_DATA_ASCII, files[i].lines, LINE_COUNT);
 	}
 
 	for (l = 0; l < LINE_COUNT; l++) {
@@ -139,7 +139,7 @@ test_fgetwln_single(void)
 	size_t len;
 	int i;
 
-	fp = pipe_feed("%ls", (const void **)data_wide, DATA_LINES);
+	fp = pipe_feed(PIPE_DATA_WIDE, (const void **)data_wide, DATA_LINES);
 	for (i = 0; i < DATA_LINES; i++) {
 		wchar_t *wstr;
 
@@ -168,7 +168,7 @@ test_fgetwln_multi(void)
 		files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
 		files[i].lines[0] = wstr;
 		files[i].lines[1] = wstr;
-		files[i].fp = pipe_feed("%ls", files[i].lines, LINE_COUNT);
+		files[i].fp = pipe_feed(PIPE_DATA_WIDE, files[i].lines, LINE_COUNT);
 	}
 
 	for (l = 0; l < LINE_COUNT; l++) {
diff --git a/test/fparseln.c b/test/fparseln.c
index daff6bd..5d7898d 100644
--- a/test/fparseln.c
+++ b/test/fparseln.c
@@ -68,7 +68,7 @@ test_fparseln(const char **data_expect, int flags)
 	FILE *fp;
 	size_t i, len, lineno = 0;
 
-	fp = pipe_feed("%s", (const void **)data_test, TEST_LINES);
+	fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_test, TEST_LINES);
 	for (i = 0; i < EXPECT_LINES; i++) {
 		char *str = fparseln(fp, &len, &lineno, NULL, flags);
 
diff --git a/test/test-stream.c b/test/test-stream.c
index 849f419..0bbb641 100644
--- a/test/test-stream.c
+++ b/test/test-stream.c
@@ -27,12 +27,13 @@
 #include <sys/wait.h>
 #include <assert.h>
 #include <unistd.h>
+#include <wchar.h>
 #include <stdio.h>
 
 #include "test-stream.h"
 
 FILE *
-pipe_feed(const char *fmt, const void **buf, int buf_nmemb)
+pipe_feed(enum pipe_data_mode mode, const void **buf, int buf_nmemb)
 {
 	FILE *fp;
 	int rc;
@@ -56,7 +57,10 @@ pipe_feed(const char *fmt, const void **buf, int buf_nmemb)
 		assert(fp);
 
 		for (line = 0; line < buf_nmemb; line++) {
-			rc = fprintf(fp, fmt, buf[line]);
+			if (mode == PIPE_DATA_ASCII)
+				rc = fprintf(fp, "%s", (const char *)buf[line]);
+			else
+				rc = fprintf(fp, "%ls", (const wchar_t *)buf[line]);
 			assert(rc >= 0);
 		}
 
diff --git a/test/test-stream.h b/test/test-stream.h
index cee4e60..8caf3fc 100644
--- a/test/test-stream.h
+++ b/test/test-stream.h
@@ -29,8 +29,13 @@
 
 #include <stdio.h>
 
+enum pipe_data_mode {
+	PIPE_DATA_ASCII,
+	PIPE_DATA_WIDE,
+};
+
 FILE *
-pipe_feed(const char *fmt, const void **buf, int buf_nmemb);
+pipe_feed(enum pipe_data_mode mode, const void **buf, int buf_nmemb);
 void
 pipe_close(FILE *fp);
 
commit beafad2657c7a57109c28f8bad9cb028c84c7dd5
Author: Guillem Jover <guillem at hadrons.org>
Date:   Sun Mar 7 00:22:59 2021 +0100

    build: Add missing proctitle unit test program

diff --git a/test/Makefile.am b/test/Makefile.am
index 90fe384..de80b12 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -41,6 +41,7 @@ check_PROGRAMS = \
 	fpurge \
 	md5 \
 	nlist \
+	proctitle \
 	proctitle-init \
 	progname \
 	pwcache \
commit 6145b561784467bc6a483f48468ba4f6a742e2fe
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 17 03:14:57 2021 +0200

    test: Do not pass NULL as the first funopen() argument
    
    Warned-by: gcc -W

diff --git a/test/funopen.c b/test/funopen.c
index 2b34f7e..65c493e 100644
--- a/test/funopen.c
+++ b/test/funopen.c
@@ -114,7 +114,7 @@ main(int argc, char **argv)
 	size_t i;
 
 	/* Test invalid hooks. */
-	fp = funopen(&tc, NULL, NULL, NULL, NULL);
+	fp = funopen(NULL, NULL, NULL, NULL, NULL);
 	assert(fp == NULL);
 	assert(errno == EINVAL);
 
commit 731b0a773903a5e631071d6070d98563a7c3cb3e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 17 02:59:59 2021 +0200

    build: Detect sed at configure time
    
    Check whether sed is available and use the implementation matching the
    requirements via the SED variable.

diff --git a/configure.ac b/configure.ac
index 1591a93..645a95b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,7 @@ AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
 
 # Checks for programs.
 AC_PROG_CC
+AC_PROG_SED
 AC_PROG_INSTALL
 AC_PROG_LN_S
 
diff --git a/man/Makefile.am b/man/Makefile.am
index 5dd37bf..9c6ad89 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -11,7 +11,7 @@ CLEANFILES = \
 SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
 
 md5.3bsd: $(srcdir)/mdX.3bsd
-	$(AM_V_GEN) sed $(SED_MD5_SUBST) $< > $@
+	$(AM_V_GEN) $(SED) $(SED_MD5_SUBST) $< > $@
 
 dist_man_MANS = \
 	LIST_CLASS_ENTRY.3bsd \
diff --git a/src/Makefile.am b/src/Makefile.am
index 7ef2013..fe9d1e6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -136,7 +136,7 @@ install-exec-hook:
 		mv $(DESTDIR)$(libdir)/libbsd*.so.* \
 		   $(DESTDIR)$(runtimelibdir)/; \
 		soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \
-		sorelprefix=`echo $(libdir) | sed -r -e 's:(^/)?[^/]+:..:g'`; \
+		sorelprefix=`echo $(libdir) | $(SED) -r -e 's:(^/)?[^/]+:..:g'`; \
 		ln -sf $$sorelprefix$(runtimelibdir)/$$soname \
 		       $(DESTDIR)$(libdir)/libbsd.so; \
 	fi
commit 50b50a4330e54b701d4a7b887deb864af26cd638
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Mar 2 05:18:04 2021 +0100

    vis: Add prototypes for strnvis() and strnunvis() variants
    
    Warned-by: gcc

diff --git a/src/unvis.c b/src/unvis.c
index 166421a..0f40a27 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -564,12 +564,16 @@ strunvis(char *dst, const char *src)
  * NetBSD: 2012,  strnunvis(char *dst, size_t dlen, const char *src);
  */
 ssize_t
+strnunvis_openbsd(char *, const char *, size_t);
+ssize_t
 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);
 
+int
+strnunvis_netbsd(char *, size_t, const char *);
 int
 strnunvis_netbsd(char *dst, size_t dlen, const char *src)
 {
diff --git a/src/vis.c b/src/vis.c
index c8e5ae8..f6261bc 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -733,12 +733,16 @@ strvis(char *mbdst, const char *mbsrc, int flags)
  * NetBSD: 2012,  strnvis(char *dst, size_t dlen, const char *src, int flag);
  */
 int
+strnvis_openbsd(char *, const char *, size_t, int);
+int
 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);
 
+int
+strnvis_netbsd(char *, size_t, const char *, int);
 int
 strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
 {
commit 25e88f6479466f2164c5dcf4a0798002e43f342e
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Mar 2 00:48:31 2021 +0100

    test: Cast literal strings to (char *) on n_name assignment
    
    The member is declared as n_name so we cannot directly assign a literal
    string constant.
    
    Warned-by: gcc

diff --git a/test/nlist.c b/test/nlist.c
index 82e24e9..a2ac228 100644
--- a/test/nlist.c
+++ b/test/nlist.c
@@ -55,11 +55,11 @@ int
 main(int argc, char **argv)
 {
 	struct nlist nl[] = {
-		{ .n_un.n_name = "main" },
-		{ .n_un.n_name = "func_pub" },
-		{ .n_un.n_name = "data_pub_uninit" },
-		{ .n_un.n_name = "data_pub_init" },
-		{ .n_un.n_name = "data_prv_init" },
+		{ .n_un.n_name = (char *)"main" },
+		{ .n_un.n_name = (char *)"func_pub" },
+		{ .n_un.n_name = (char *)"data_pub_uninit" },
+		{ .n_un.n_name = (char *)"data_pub_init" },
+		{ .n_un.n_name = (char *)"data_prv_init" },
 		{ .n_un.n_name = NULL },
 	};
 	int rc;
commit 04a8fb2469439ef3397062b4b1792d45bc95f469
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Mar 2 00:48:02 2021 +0100

    Add missing prototypes to functions
    
    Warned-by: gcc

diff --git a/src/explicit_bzero.c b/src/explicit_bzero.c
index 52a7517..d223631 100644
--- a/src/explicit_bzero.c
+++ b/src/explicit_bzero.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: explicit_bzero.c,v 1.3 2014/06/21 02:34:26 matthew Exp $ */
+/*	$OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
 /*
  * Public domain.
  * Written by Matthew Dempsky.
@@ -6,6 +6,9 @@
 
 #include <string.h>
 
+__attribute__((__weak__)) void
+__explicit_bzero_hook(void *, size_t);
+
 __attribute__((__weak__)) void
 __explicit_bzero_hook(void *buf, size_t len)
 {
diff --git a/src/setproctitle.c b/src/setproctitle.c
index ff32aa3..d3e1087 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -222,6 +222,10 @@ setproctitle_init(int argc, char *argv[], char *envp[])
 #define SPT_MAXTITLE 255
 #endif
 
+__printflike(1, 2)
+void
+setproctitle_impl(const char *fmt, ...);
+
 void
 setproctitle_impl(const char *fmt, ...)
 {
commit 4f68a88f5519e1bbc8b339dd48882f7f8c613edf
Author: Guillem Jover <guillem at hadrons.org>
Date:   Fri Feb 19 06:55:17 2021 +0100

    build: Add compiler warnings support
    
    Detect as many warnings as possible during configure and enable them
    if the user did not supply any, so that any such problem can be spotted
    and fixed.

diff --git a/.gitignore b/.gitignore
index c805925..bece823 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,5 +20,4 @@ build-aux/
 configure
 config.*
 libtool
-m4/
 stamp-h1
diff --git a/configure.ac b/configure.ac
index 09cb310..1591a93 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,9 +52,45 @@ AC_PROG_INSTALL
 AC_PROG_LN_S
 
 # Set default compiler variables
-if test "$user_CFLAGS" = unset && test "$GCC" = yes; then
-  CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter"
-fi
+AS_IF([test "$user_CFLAGS" = unset], [
+  LIBBSD_CHECK_COMPILER_FLAG([-Wall])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wextra])
+
+  LIBBSD_CHECK_COMPILER_FLAG([-Wbad-function-cast])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wc99-c11-compat])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wcast-align])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wdeclaration-after-statement])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wdocumentation])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wduplicated-branches])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wduplicated-cond])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wformat -Wformat-security])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wformat=2])
+  LIBBSD_CHECK_COMPILER_FLAG([-Winit-self])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wlogical-not-parentheses])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wlogical-op])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wmissing-declarations])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wmissing-format-attribute])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wmissing-prototypes])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wnested-externs])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wno-missing-field-initializers])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wno-nonnull-compare])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wno-tautological-constant-out-of-range-compare])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wno-unused-parameter])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wnull-dereference])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wold-style-definition])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wpointer-arith])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wregister])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wrestrict])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wshadow])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wshift-negative-value])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wsizeof-array-argument])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wstrict-prototypes])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wswitch-bool])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wvla])
+  LIBBSD_CHECK_COMPILER_FLAG([-Wwrite-strings])
+
+  CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
+])
 
 # Checks for libraries.
 AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits],
diff --git a/m4/.gitignore b/m4/.gitignore
new file mode 100644
index 0000000..10fb5d4
--- /dev/null
+++ b/m4/.gitignore
@@ -0,0 +1,2 @@
+*.m4
+!libbsd*.m4
diff --git a/m4/libbsd-compiler.m4 b/m4/libbsd-compiler.m4
new file mode 100644
index 0000000..b655b83
--- /dev/null
+++ b/m4/libbsd-compiler.m4
@@ -0,0 +1,24 @@
+# Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+
+# LIBBSD_CHECK_COMPILER_FLAG
+# -------------------------
+AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
+  AS_VAR_PUSHDEF([libbsd_varname_cache], [libbsd_cv_cflags_$1])
+  AC_CACHE_CHECK([whether $CC accepts $1], [libbsd_varname_cache], [
+    m4_define([libbsd_check_flag], m4_bpatsubst([$1], [^-Wno-], [-W]))
+    AS_VAR_COPY([libbsd_save_CFLAGS], [CFLAGS])
+    AS_VAR_SET([CFLAGS], ["-Werror libbsd_check_flag"])
+    AC_COMPILE_IFELSE([
+      AC_LANG_SOURCE([[]])
+    ], [
+      AS_VAR_SET([libbsd_varname_cache], [yes])
+    ], [
+      AS_VAR_SET([libbsd_varname_cache], [no])
+    ])
+    AS_VAR_COPY([CFLAGS], [libbsd_save_CFLAGS])
+  ])
+  AS_VAR_IF([libbsd_varname_cache], [yes], [
+    AS_VAR_APPEND([LIBBSD_COMPILER_FLAGS], [" $1"])
+  ])
+  AS_VAR_POPDEF([libbsd_varname_cache])
+])


More information about the libbsd mailing list